Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix field visibility of object comprehension fields to inherit #1140

Conversation

johnbartholomew
Copy link
Collaborator

This should make C++ Jsonnet match the existing behaviour of Go-Jsonnet.

Object comprehensions do not support differing field visibility, that is an object comprehension with a "hidden" or "forced-visible" field such as {[k]::1 for k in ["x"]} is rejected with a syntax error.

Intuitively the {[key_expr]: value_expr for x in ...} syntax should behave similarly to a normal (non-comprehension) object that uses default field visibility. Default field visibility is to 'inherit' visibility when merging objects with the + operator, and this is the existing behaviour of Go-Jsonnet.

Example case:

./jsonnet -e '{"one":: "base"} + {[k]: "derived" for k in ["one"]}'

Before this commit, Go-Jsonnet output:
{ }

Before this commit, C++ Jsonnet output:
{ "one": "derived" }

After this commit, both produce { }

Fixes #1111

This should make C++ Jsonnet match the existing behaviour of Go-Jsonnet.

Object comprehensions do not support differing field visibility, that is
an object comprehension with a "hidden" or "forced-visible" field such as
`{[k]::1 for k in ["x"]}` is rejected with a syntax error.

However, intuitively the `{[key_expr]: value_expr for x in ...}` syntax
seems like it should behave similarly to a normal (non-comprehension) object
that uses default field visibility. Default field visibility is to 'inherit'
visibility when merging objects with the + operator, and this is the existing
behaviour of Go-Jsonnet.

Example case:

./jsonnet -e '{"one":: "base"} + {[k]: "derived" for k in ["one"]}'

Before this commit, Go-Jsonnet output:
{ }

Before this commit, C++ Jsonnet output:
{ "one": "derived" }

Bug report:
google#1111
@johnbartholomew johnbartholomew force-pushed the fix-object-comprehension-visibility-1111 branch from 2ad5d66 to 4b914fb Compare March 23, 2024 14:02
@johnbartholomew johnbartholomew merged commit 4b914fb into google:master Mar 23, 2024
6 checks passed
@johnbartholomew johnbartholomew deleted the fix-object-comprehension-visibility-1111 branch March 23, 2024 14:23
simu added a commit to appuio/component-openshift4-monitoring that referenced this pull request Oct 31, 2024
Some upstream Jsonnet hides the `runbook_url` annotation on alerts.

Because of that, some of our patches which insert the `runbook_url`
annotation don't work correctly with go-jsonnet 0.20.0, which correctly
inherits field visibility in object comprehension (e.g.
`com.makeMergeable()`). This behavior will also be fixed in an upcoming
C++ jsonnet version, cf. google/jsonnet#1140 so
we adjust the component to make all `runbook_url` annotations visible.

Notably, the upstream Jsonnet which hides the annotation also sets it to
`null`, so we can then clean up the unwanted `runbook_url: null`
annotations by calling `std.prune()` on the annotations object.
stephenamar-db pushed a commit to databricks/sjsonnet that referenced this pull request Jan 3, 2025
…lity, not Unhide (#255)

This PR changes the default visibility of fields in objects created by
`std.mergePatch`: previously they were at `Unhide` visibility,
equivalent to the `:::` operator, but as of this PR they are now at
`Normal` standard visibility.

Concretely, previously 

```sjsonnet
{a:: 0} + std.mergePatch({a: 1}, {})
```

would return `{a: 1}` but after this patch it returns `{a:: 1)`, i.e. it
preserves the hidden field.

It turns out that v0.20.0 of google/jsonnet and google/go-jsonnet also
differ in their behavior here. That, in turn, is due to a behavior
difference in the default visibility of fields in object comprehension
results: jsonnet marks object comprehension fields as forced-visible,
while go-jsonnet marks them as inherited visibility; see
google/jsonnet#1111.

jsonnet accepted google/jsonnet#1140 to match
go-jsonnet's behavior.

Note that sjsonnet already matches go-jsonnet's behavior for object
comprehensions: we only have a difference in `std.mergePatch` because
our current implementation explicitly hardcodes Unhide visibility.

This PR changes that mergePatch-specific behavior to match the current
go-jsonnet (and future jsonnet) behavior.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different behavior of hidden status inheritance between Jsonnet and Go-Jsonnet
1 participant