Is it possible to modify the FlyteContext in a way...
# ask-the-community
b
Is it possible to modify the FlyteContext in a way that allows us to add attributes to the ExecutionParamaters for example? The situation is that our flyte launch plans are executed from a separate cron system that has it's own execution_id that we want to reference in our tasks for things like tagging infrastructure that is instantiated during the task. The reason for not just adding the cron execution_id to the inputs is that we also want to take advantage of caching and if the execution id is passed as part of the input parameters then the task outputs will always be associated with that single execution. Alternatively it would be amazing to be able to configure how the input is hashed so that only certain input parameters are considered for the key to the cache.
k
yes, you are able to add attributes to ExecutionParamaters. here is an example. https://github.com/flyteorg/flytekit/pull/1725/files#diff-b7d319a6a758a21cb9e78fe6c150fdbf4f5ec7173a0468253655601bbf86aeb3R49
Copy code
ctx.user_space_params._attrs["GET_ORIGINAL_TASK"] = True
b
And would this user_space_param be persisted across the other tasks if I did this modification in the beginning? I'm thinking something like :
Copy code
@task
def task_1(execution_id:str):
  ctx = FlyteContextManager.get_current_context()
  ctx.user_space_params._attrs["GET_ORIGINAL_TASK"] = True

@task
def task_2():
  ctx = FlyteContextManager.get_current_context()
  print(ctx.user_space_params._attrs["GET_ORIGINAL_TASK"]) 

@workflow()
def wf(execution_id:str)->None:
  task_1_output = task_1()
  task_2_output = task_2()
  task_1_output >> task_2_output
k
ahh, flytekit context can’t be shared across the tasks. how about passing an env to the workflow?
b
Oh you can pass in an environment to the workflow?
k
yes, you can. you add it through
pyflyte run --env
UI is not supported yet
b
Ah so when the launchplan is executed by our system we could run it while passing in the environment variables.
k
ya also, launchplan can have default env vars set