open-policy-agent

cast_set deprecated. What’s the replacement?


I’m currently running OPA version 0.39.0, but I’m trying to upgrade to a more recent version and am getting the following issue:

rego_type_error: deprecated built-in function calls in expression: cast_set

I tried looking through the docs and release notes but don’t see anything about cast_set being deprecated. Is there a work around to continue using a deprecated function or is there a suggested replacement?

Also, is OPA following SemVer, with Major.Minor.Patch? Would expect subsequent versions after 0.39.0 to still be compatible with it since we are currently on 0.46.1.


Solution

  • You did not state which command you are running when you see that error. The only one that should produce that is opa check --strict, where the very purpose of the command is to check for things like unused variables, use of deprecated functions, etc... i.e. strict mode.

    I just tried some other commands, like opa build and opa run, and none of them seem to produce that warning - and they shouldn't.

    The idiomatic way of creating a set from an array, is to use a set comprehension:

    my_arr := [1, 2, 3]
    my_set := {x | x := my_arr[_]} 
    
    my_set == {1, 2, 3}
    

    We try hard to not make backwards compatibile changes in OPA, and if you're seeing this error outside of strict mode, please open an issue. A command like opa check --strict is however meant to warn about things like this, so that's going to be an obvious exception.