open-policy-agent/opa

object.subset method does not evaluate correctly for all subset permutations

Closed this issue · 3 comments

Short description

Hi, this is very similar to a previous bug, which can be found here: #5968
I notice although the exact error presented in the example of this issue was corrected, the method still does not evaluate correctly for all cases. Specifically, when the subset skips a middle values, and also disordered subsets.

Steps To Reproduce

rego code for skipped value:
array1 := [1,2,3,4,5] array2 := [1,3,5] object.subset(array1, array2)
test: https://play.openpolicyagent.org/p/2wGtvbgy63

also, with disordered array:
array1 := [1,2,3,4,5] array2 := [5,4,3,2,1] object.subset(array1, array2)
test: https://play.openpolicyagent.org/p/VIOfMWygps

Expected Result

For both bases, it should evaluate to true, but I get false.

I'm not sure if disordered subsets are meant to be included as true cases, but it would be helpful if it were, or perhaps create two methods with evaluate subset, distinguished by ordered and disordered.

Hi there! You'll find the rules for ordering in the policy reference: https://www.openpolicyagent.org/docs/latest/policy-reference/#builtin-object-objectsubset

If you want order to be ignored, you can make either both or the subset a set instead of an array.

I converted both to set from array and it works, thank you for the update

Thanks! Closing this then as I believe the function works as documented.