h

    Hui Zheng

    1 year ago
    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
    with Flow('Flow with new context') as flow:
        # Could we add new objects to prefect.context here?
    
        task_1_use_new_context_object()
    Dylan

    Dylan

    1 year ago
    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
    h

    Hui Zheng

    1 year ago
    Hi Dylan, I just realized that the the context is not accessible at the scope of flow definition, it’s only accessible within tasks
    Dylan

    Dylan

    1 year ago
    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