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

Trouble with binary expression in doc generation #995

Closed
jrozentur opened this issue Oct 9, 2018 · 1 comment
Closed

Trouble with binary expression in doc generation #995

jrozentur opened this issue Oct 9, 2018 · 1 comment
Labels

Comments

@jrozentur
Copy link

I am trying to return a document to the rest call. The document contains results of a match array, and a binary conclusion

> accept[result]{
 c=3
 a=[1,2,3]
 result={"v":a}
}
Rule 'accept' defined in package repl. Type 'show' to see rules.
> accept
[
  {
    "v": [
      1,
      2,
      3
    ]
  }
]

This is correct, but let's add a conditional:

> accept[result]{
 c=3
 a=[1,2,3]
 result={"ok":c==0, "v":a}
}
Rule 'accept' defined in package repl. Type 'show' to see rules.
> accept
[]

Why is the resulting doc empty? c is a bound variable, and I should be able to use it in an expression, the problem is when the expression is binary

@tsandall tsandall added the bug label Oct 10, 2018
@tsandall
Copy link
Member

tsandall commented Oct 10, 2018

Under the hood, OPA is rewriting the == operation as a unification operation without checking whether the result of the == operation is required. Unification fails (since 3 != 0) so the query ends up undefined. This is a bug. Thanks for reporting it--it should be a quick fix.

tsandall added a commit to tsandall/opa that referenced this issue Oct 10, 2018
In a660d8f we added a rewriting stage that converts == to unification.
This simplifies evaluation and allows the rule index to be used,
however, the rewriting was incorrectly applied to == expressions that
are intended to yield a true/false value (and not undefined).

Fixes open-policy-agent#995

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit that referenced this issue Oct 10, 2018
In a660d8f we added a rewriting stage that converts == to unification.
This simplifies evaluation and allows the rule index to be used,
however, the rewriting was incorrectly applied to == expressions that
are intended to yield a true/false value (and not undefined).

Fixes #995

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants