Skip to content
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

Merged
merged 3 commits into from
Mar 15, 2024

Conversation

pipt
Copy link
Contributor

@pipt pipt commented Mar 14, 2024

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.

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.
@@ -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(""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this BeNil instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes 😭

@@ -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 == "" {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@macebake macebake left a 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!!

pipt added 2 commits March 15, 2024 12:23
So that we can return nil when we need
Because we correctly return nil now.
@pipt pipt merged commit 9baedf1 into master Mar 15, 2024
1 check passed
@pipt pipt deleted the pip/dont-set-attributes-if-theyre-not-in-the-input branch March 15, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants