Variables - Automatic update code

Options
agardenat
agardenat Registered Posts: 2

Hello !

I read on the documentation that global variables can be dynamically modified at project run by auto execution the get_variables() code defined in Administration / Variables Automatic update code.

It seems nice but as I see it is Jython only, is there any way to use some contextual data like custom variables / user property / username / etc from there ?

Thanks in Advance !

Antoine

Answers

  • Zach
    Zach Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 153 Dataiker
    edited July 17
    Options

    Hi @agardenat
    ,

    You won't be able to access that information using the automatic update code since it uses Jython.

    As an alternative, you could use Python code in a scenario to set the global variables. This uses regular Python, so you have full access to Python modules.

    Preview of the scenario:

    image.png

    Example code that sets the "my_var" global variable:

    from dataiku.scenario import Scenario
    
    scenario = Scenario()
    
    scenario.set_global_variables(
        my_var="foo"
    )

    Reference documentation: Scenarios (in a scenario)

    Thanks,

    Zach

  • agardenat
    agardenat Registered Posts: 2
    Options

    Hi @ZachM

    Thanks for your answer.

    I sure can do that, but I will miss the "automatic" part which made it transparent, with no need to add code to scenarios.

    Thanks,

    Antoine

  • Zach
    Zach Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 153 Dataiker
    Options

    Hi @agardenat
    ,

    You can update the variables automatically by adding a trigger to the scenario. For example, a time-based trigger will cause the variables to be updated on a schedule, such as once every day.

    Reference: Scenario Triggers.

  • Axolotl
    Axolotl Registered Posts: 13
    Options

    Hi,

    I believe the question was to be able to do such thing (set/update a variable dynamically) without using scenarios.

    I have the same needs. For each project, I need to parameterise dynamically, some variables so that I can retrieve the values (user, time) at each execution and this, not in a scenarios (users can execute recipe outside a scenario).
    This will allows to trace the use of runs during the design period.

    Is there a way to do that ?
    Thanks

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 1,726 Neuron
    Options

    Why is not possible to use Scenarios and Scenario variables which are perfect as they are calculated at run time? Running parts of the flow randomly is not a deterministic approach. You can break your flow build in multiple scenarios to allow for piece meal building. I would suggest you start a new thread as it seems you have a slightly different requirement.

  • Axolotl
    Axolotl Registered Posts: 13
    Options

    Yes sorry, I was in this thread because I found the same way as agardenat to do such thing : global variables can be dynamically modified at project run by auto execution the get_variables() code defined in Administration / Variables Automatic update code.

    I fully agree with you for the scenario usage. But I canot prevent a user starts a new project, then create a handle on data then execute a recipe on it. For this use case, a global variables that can be dynamically modified at project level during execution would be helpfull.

Setup Info
    Tags
      Help me…