Hi, can imported variables be used in local variab...
# help
j
Hi, can imported variables be used in local variables? I know they are working but sometimes it seems that the local variable is not correctly calculated when using an imported variable ­čśĽ (Edit: Everything works 100% of the time if I move the condition directly to the condition block of a rule)
o
Hi Jan, Would it be possible for you to share a minimal example? In the meantime I will try to reproduce the issue myself.
j
I will try but it might take some time
a
This looks like a bug, sorry! The variable definitions from the imports and local are merged together in a non-deterministic order. Unfortunately, if a variable references another variable, it seems like the order they are defined matters when they are evaluated (this is true even if we only have local variables!). That shouldn't be the case - tracking it at https://github.com/cerbos/cerbos/issues/1746.
j
Good to know. I didnÔÇÖt know or expect that other local variables can be referenced. But I would expect that the imported variables are evaluated before evaluating the local variables
a
Yeah, I reckon imported variables and local variables ought to be able to reference each other in either direction (as long as that doesn't produce a cycle) because then you don't have to think about where they are defined. I can definitely see use cases where you might want to "inject" a local value into the common definitions that you're importing.
j
Maybe a functions feature would be better? ­čÖé Injecting sounds like a debugging nightmare ­čśë
a
We do have adding functions etc out there as a feature request - but I suspect it's a pretty complex thing to both implement and use