hi team, wondering if we could override/enrich the...
# ask-community
h
hi team, wondering if we could override/enrich the prefect context? i.e. I would like to have a task that does
Copy code
from prefect import context as prefect_context, task

@task
def enrich_context():
    prefect_context["custom_key"] = 1

@task
def main_task():
    value = prefect_context["custom_key"]
    print(value)

with Flow("test-enrich_context") as flow:
   _enrich_context_task = enrich_context()
   main_task(upstream_tasks=[_enrich_context_task])
k
Hey @haven, you can’t do this and have it carry to downstream tasks. I suggest you use the KV Store to persist small pieces of info. Have you seen the docs ?
h
ah I see. unfortunately the key-value pair that I'm trying to persist is a Python object. I'd probably try to build a local context then. Thanks!
k
You can persist it and keep track of the location with the store maybe
👍 1