-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't set attributes that aren't in the input #101
Don't set attributes that aren't in the input #101
Conversation
When an attribute wasn't in the input data, we weren't handling that correctly and would set the value of the attribute in the catalog to the Go empty value (for example, we'd set a number attribute to 0 if that attribute wasn't set in the input for an entry). This has been fixed by distinguishing when the value we get back from Otto is null or undefined, and not including that attribute.
expr/js_eval_test.go
Outdated
@@ -80,29 +80,29 @@ var _ = Describe("Javascript evaluation", func() { | |||
topLevelSrc := "$.metadata" | |||
evaluatedResult, err := EvaluateSingleValue[string](ctx, topLevelSrc, sourceEntry, logger) | |||
Expect(err).NotTo(HaveOccurred()) | |||
Expect(evaluatedResult).To(Equal("")) | |||
Expect(*evaluatedResult).To(Equal("")) |
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.
should this BeNil
instead?
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.
Yes 😭
output/marshal.go
Outdated
@@ -136,14 +136,14 @@ func MarshalEntries(ctx context.Context, output *Output, entries []source.Entry, | |||
if err != nil { | |||
return nil, errors.Wrap(err, fmt.Sprintf("aliases.%d: evaluating entry alias", idx)) | |||
} | |||
if alias == "" { | |||
if alias == nil || *alias == "" { |
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 feel like it's worth explaining in a brief comment why we have to do this, but I'm not sure exactly where.
You could call it out in a couple of places separately, like here in MarshalEntries
and somewhere in js_eval.go
- just because this may feel like a redundant check if you don't know what's going on
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.
Fixing the comment about BeNil
means that this extra check isn't needed now, because EvaluateResultType
now returns a pointer, not ""
when you ask for a string but we can't evaluate to a string.
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.
left a couple of comments but LGTM!!
So that we can return nil when we need
Because we correctly return nil now.
When an attribute wasn't in the input data, we weren't handling that correctly and would set the value of the attribute in the catalog to the Go empty value (for example, we'd set a number attribute to 0 if that attribute wasn't set in the input for an entry).
This has been fixed by distinguishing when the value we get back from Otto is null or undefined, and not including that attribute.