opa icon indicating copy to clipboard operation
opa copied to clipboard

Docs on default functions should mention risk of undefined arguments

Open anderseknert opened this issue 2 years ago • 2 comments
trafficstars

The docs on the default keyword describes the new default function feature like:

The value of a default function follows the same conditions as that of a default rule.

That's not really the case though, as default functions provides no guarantess as for evaluating in case an undefined attribute is provided in any of the arguments passed. This is likely not what most would expect from having used default values for rules, so provided this can't be fixed it needs to be clearly documented that default functions provide no guarantees similar to default rules.

anderseknert avatar Oct 02 '23 10:10 anderseknert

Can you please provide an example of this case?

ashutosh-narkar avatar Oct 02 '23 21:10 ashutosh-narkar

Sure:

package p

default x(_) := "default"

x_is := x(input.undefined)
$ opa eval -f pretty -d p.rego data.p.x_is
undefined

The root cause being the same as described in #1877, but now in one more place where people likely/rightly would share the same expectation. Fixing anything would be great, but also breaking. So, clearly documenting the behavior here seems like the best course of action now.

anderseknert avatar Oct 02 '23 21:10 anderseknert