Have a question about Prefect Context. I Context document under Core Concepts / Execution as well as API Latest / prefect.utilities Context. Both seem to say that users can store items in the context, being careful to not step on any Prefect items, of course, and then retrieve them later. I am attempting to do that but running into trouble. I have created a simple task which receives a "label" to store a time value under. For example, "Start_Flow" would be used to store a time.time() value into the context. That part seems to be working correctly in the task as I can store and then print the stored value. However, in a subsequent task, when I retrieve the "Start_Flow" item from the context, I get a None value. Is there something that I am missing about Context? I am using code similar to the following:
To store:
prefect.context[label] = time.time()
To retrieve:
time_val = prefect.context.get(label)
k
Kevin Kho
05/19/2021, 8:02 PM
Hi @Jeff Williams, once the context is initialized, you can’t modify it. The place to store it through the context would be config.toml or you can use the
Thanks @Kevin Kho - Those were the two documents that I had been referencing. I got the impression that it was a fluid context that could be utilized in the flow / tasks rather than it being static after initialization. I guess I will have to re-think some things...
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.