https://prefect.io logo
h

Hui Zheng

10/02/2020, 4:43 PM
Hello, I have a question about
prefect context
. It seems a powerful way to share common variables and objects among tasks. Is it possible to add new objects or variables inside the flow definition which then to be used by the tasks later? https://docs.prefect.io/core/concepts/execution.html#modifying-context-at-runtime such as
Copy code
with Flow('Flow with new context') as flow:
    # Could we add new objects to prefect.context here?

    task_1_use_new_context_object()
d

Dylan

10/02/2020, 5:03 PM
Hi @Hui Zheng! As long as you pass things into context before the flow run starts, we totally agree! We definitely suggest staying away from modifying context at runtime
👍 1
h

Hui Zheng

10/05/2020, 11:04 PM
Hi Dylan, I just realized that the the context is not accessible at the scope of flow definition, it’s only accessible within tasks
d

Dylan

10/06/2020, 2:30 PM
You can pass additional objects to context at the beginning of a flow run, however
Check out the “Run” page in the UI for a flow