-
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
any
does not behave like a typical or
#3002
Comments
any
does not behave like a typical or
when we have undefined terms.any
does not behave like a typical or
Thanks for your detailled report! 👍 Please bear in mind that When you call any([
data.users["charlie"].groups["groupA"],
data.users["charlie"].groups["groupB"],
data.users["charlie"].groups["groupZ"],
]) the evaluation will not even invoke In your example, I'd introduce a partial rule the builds the array of the user's groups: user_groups[g] {
data.users[input.subject].groups[g]
} ☝️ This will behave like you'd want it to, I think: It will be a set containing all the groups. It will always be defined. You can query it for a specific one, or_any3 {
count(user_groups & {"groupA", "groupC", "groupZ"}) > 0
} Does this help? 😃 |
I thought we'd deprecated I'm inclined to mark these built-ins as deprecated and put some examples into the docs instead. |
There's a ticket for deprecating them here #2437 |
Would fetching all user groups as a set, affect the performance in any way? Is that better than checking if a particular group exists? That matters for use as in some cases the group list is quite large. |
Lookups like One option (until #822 is fixed) is to implement (one of) two versions: # use this version if you require the entire set to be computed at least once
user_groups := {g |
some g
data.users[input.user].groups[g]
}
# use this version if you ONLY need to check for existence of specific groups
user_group[g] {
some g
data.users[input.user].groups[g]
} |
any
does not behave like a typicalor
when we have undefined terms or objects.Behavior
any
should behave exactly like when it gets written as aor
the rule body.undefined
,any
returnsundefined
. It should evaluateundefined
tofalse.
true
as existence of the object.Steps to Reproduce the Problem
https://play.openpolicyagent.org/p/96S1COuUol
Here
or_seperate
,or_any1
,or_any2
,or_any3
should all be true.Adding the data.json here
REPL results
Additional Info
The text was updated successfully, but these errors were encountered: