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

format: make groupIterable sort by row #3851

Merged
merged 3 commits into from
Oct 4, 2021

Conversation

srenatus
Copy link
Contributor

@srenatus srenatus commented Oct 4, 2021

Before, it depended on the elements being passed in ordered by their rows.
Before #3823, the iteration
order was the same as the row order; but with sorting the keys slice (which
determines iteration order) on creation, that was changed.

Now, we'll sort the elements within groupIterable.

Fixes #3849.


For #3849, this means that the ordering that matters for formatting literal objects in rego code is
the row ordering. This PR reverts the behavioural change that would make the formatter print those
with their keys sorted.

globals = {
"foo": "bar",
"fizz": "buzz",
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This reverts the crucial bit of #3823 that should have given this bug away but that I didn't notice in its full extent.

@srenatus srenatus marked this pull request as ready for review October 4, 2021 06:37
Before, it depended on the elements being passed in ordered by their rows.
Before open-policy-agent#3823, the iteration
order was the same as the row order; but with sorting the keys slice (which
determines iteration order) on creation, that was changed.

Now, we'll sort the elements within `groupIterable`.

Fixes open-policy-agent#3849.

Signed-off-by: Stephan Renatus <[email protected]>
Since map iteration is randomized in golang, this benchmark didn't
actually measure what was intended, but rather the presence or ab-
sence of duplicate keys.

Now, we'll create a set of keys to insert before, and either shuffle
it or use it in its increasing order: to call `(Object).Insert()` in
a loop.

Signed-off-by: Stephan Renatus <[email protected]>
@srenatus
Copy link
Contributor Author

srenatus commented Oct 4, 2021

Added the forward-ported CHANGELOG and capabilities from 0.33.1.

@srenatus
Copy link
Contributor Author

srenatus commented Oct 4, 2021

Approved in #3854

@srenatus srenatus merged commit b5e7139 into open-policy-agent:main Oct 4, 2021
@srenatus srenatus deleted the sr/issue-3849/fmt-change branch October 4, 2021 12:14
dolevf pushed a commit to dolevf/opa that referenced this pull request Nov 4, 2021
* format: make groupIterable sort by row

Before, it depended on the elements being passed in ordered by their rows.
Before open-policy-agent#3823, the iteration
order was the same as the row order; but with sorting the keys slice (which
determines iteration order) on creation, that was changed.

Now, we'll sort the elements within `groupIterable`.

Fixes open-policy-agent#3849.

Also includes:

* ast/term_bench_test: fix benchmark

Since map iteration is randomized in golang, this benchmark didn't
actually measure what was intended, but rather the presence or ab-
sence of duplicate keys.

Now, we'll create a set of keys to insert before, and either shuffle
it or use it in its increasing order: to call `(Object).Insert()` in
a loop.

* CHANGELOG/capabilities: update for v0.33.1 bugfix release

Signed-off-by: Stephan Renatus <[email protected]>
Signed-off-by: Dolev Farhi <[email protected]>
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.

opa fmt changed for with x as { ... } expressions in 0.33.0
1 participant