-
Notifications
You must be signed in to change notification settings - Fork 1
Trying to fix issue with NaN, Inf, -Inf #45
Trying to fix issue with NaN, Inf, -Inf #45
Conversation
Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
@dsuhinin could you add a high level walkthrough of this in the description please? Why bring in the custom |
Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
Is any python unit test solved with any of this?
|
answered in a description. |
Thanks, Dmitry! I really appreciate the extra context. You probably checked this, but was it not possible to hook into the unmarshalling of a single property? It feels a bit cumbersome to include all the JSON source code. We should probably document this in the README. Any new contributor with Go knowledge will most likely be put off by this JSON code. It is also unclear which parts we changed and whether it's possible to update the JSON code if needed. If there's truly no better way, then I think this is fine, but it would be best to summarize this in an ADR note. |
emmm, Im not sure, about another approach really. Maybe, maybe it could be but it is hard to say. Logical way to solve this custom behaviour of If there's truly no better way, then I think this is fine, but it would be best to summarize this in an ADR note.
|
I can't see any problem to use own |
Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
Can't we do something along the lines of
|
what I had in mind last time we discussed this is exactly what Florian proposed above in #45 (comment) |
Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
func (p *HTTPRequestParser) ParseBody(ctx *fiber.Ctx, input proto.Message) *contract.Error { | ||
if protojsonErr := protojson.Unmarshal(ctx.Body(), input); protojsonErr != nil { | ||
if jsonErr := json.Unmarshal(ctx.Body(), input); jsonErr != nil { | ||
var unmarshalTypeError *json.UnmarshalTypeError | ||
if errors.As(jsonErr, &unmarshalTypeError) { | ||
result := gjson.GetBytes(ctx.Body(), unmarshalTypeError.Field) | ||
|
||
return contract.NewError( | ||
protos.ErrorCode_INVALID_PARAMETER_VALUE, | ||
fmt.Sprintf("Invalid value %s for parameter '%s' supplied", result.Raw, unmarshalTypeError.Field), | ||
) | ||
return contract.NewError( | ||
protos.ErrorCode_INVALID_PARAMETER_VALUE, | ||
fmt.Sprintf("Invalid value %s for parameter '%s' supplied", result.Raw, unmarshalTypeError.Field), | ||
) | ||
} | ||
} | ||
|
||
return contract.NewError(protos.ErrorCode_BAD_REQUEST, err.Error()) | ||
return contract.NewError(protos.ErrorCode_BAD_REQUEST, protojsonErr.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nojaf @jgiannuzzi protojson
doesn't provide any information about the filed, that's why I've decided to fallback to json
validation. a bit ugly and strange but there is no new failing tests. what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable, we want to know what is up when things fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct. I tried to only keep protojson
but it is absolutely trick then to find the field
name where it failed. We can document that probably, because it is a bit confusing.
@@ -1,4 +1,4 @@ | |||
//nolint:ireturn | |||
// nolint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does this need to change in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by some reason it started failing. Ill double check that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen this before, we should update Go and/or the linter. I believe this was fixed somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please update the PR description with the current approach? and maybe keep the previous description under a heading "Previous description (for context)"?
sure, Ill update description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me!
I'm glad this turned out so elegantly!
Nice job, both of you!
Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
#45 Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
jgiannuzzi/mlflow-go#45 Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
jgiannuzzi/mlflow-go#45 Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
jgiannuzzi/mlflow-go#45 Signed-off-by: Software Developer <7852635+dsuhinin@users.noreply.github.com>
Current solution
to be fully compatible with original
MLflow
we have to use the samemarshaller/unmarshaller
->protojson
fromgoogle.golang.org/protobuf/encoding/protojson
package. By using suchmarshaller/unmarshaller
helps out of the box correctly handle unusual cases related toNaN
,Inf
and-Inf
values.Previous description (for context)
A bit of context and answers:
-- custom
json
serialiser allows to correctly wrap/unwrap such a constants like:Nan
,Inf
,+Inf
,-Inf
. Unfortunately originalcustom
json serialiser worked a bit differently thenMLFlow
behaves. It allows parsingNan
,Inf
,+Inf
,-Inf
when they are literal values like:but unfortunately
Mlflow
sends such values as a string values like:that's why I've changed it to support what Mlflow wants and as a result pull it to our codebase.
-- probably the same answer like first item. All the
Nan
,Inf
,+Inf
,-Inf
values should be serialised as a string values.-- yes, now all the
rest
tests are green.