https://cerbos.dev logo
#help
Title
# help
j

Jan Kühnlein

08/10/2023, 12:05 PM
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

oguzhan

08/10/2023, 12:18 PM
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

Jan Kühnlein

08/10/2023, 12:58 PM
I will try but it might take some time
a

Andrew Haines (Cerbos)

08/11/2023, 10:59 AM
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

Jan Kühnlein

08/11/2023, 11:05 AM
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

Andrew Haines (Cerbos)

08/11/2023, 11:09 AM
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

Jan Kühnlein

08/11/2023, 11:34 AM
Maybe a functions feature would be better? 🙂 Injecting sounds like a debugging nightmare 😉
a

Andrew Haines (Cerbos)

08/11/2023, 11:37 AM
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