-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Inconsistent OPA number handling #5585
Comments
Adding to this, evaluation differes between rule head and rule body in this regard: https://play.openpolicyagent.org/p/DujkIZh56k With package play
# true
x := input.i == 1.0
# not true
allow {
input.i == 1.0
} The compiler rewrites the former to use package play
x := __local0__ { true; __local1__ = input.i; equal(__local1__, 1.0, __local0__) }
allow = true { input.i = 1.0 } |
Huh that's surprising. I would have expected the stage that rewrites equal to unification to cover both cases. |
Fixes: open-policy-agent#5585 Signed-off-by: Ashutosh Narkar <[email protected]>
Earlier the trie's scalar used map[ast.Value]trieNode. This resulted in unexpected key comparison results such as 1 != 1.0 when key types were ast.Number for example. This change updates the scalar to use a util.HashMap instead that will utilize ast.Compare to perfom key comparisons. Fixes: open-policy-agent#5585 Signed-off-by: Ashutosh Narkar <[email protected]>
Earlier the trie's scalar used map[ast.Value]trieNode. This resulted in unexpected key comparison results such as 1 != 1.0 when key types were ast.Number for example. This change updates the scalar to use a util.HashMap instead that will utilize ast.Compare to perfom key comparisons. Fixes: open-policy-agent#5585 Signed-off-by: Ashutosh Narkar <[email protected]>
Earlier the trie's scalar used map[ast.Value]trieNode. This resulted in unexpected key comparison results such as 1 != 1.0 when key types were ast.Number for example. This change updates the scalar to use a util.HashMap instead that will utilize ast.Compare to perfom key comparisons. Fixes: #5585 Signed-off-by: Ashutosh Narkar <[email protected]>
Short description
When using aliases or variables from a path, number type coercion doesn't work consistently. You get into a scenario where 1.0 == 1 evals to false. This can be avoided assigning the aliased value to an intermediary rule, however this behavior is not predictable and should get fixed.
Example:
Input:
Rule:
Output:
Steps To Reproduce
Playground where this is reproduced and workaround is provided https://play.openpolicyagent.org/p/RbcP7xO0eW (replace 1 for 1.0 in oneDotZero, rego playground changes this automatically when publishing)
Expected behavior
Using aliases should behave similarly to other expressions
The text was updated successfully, but these errors were encountered: