Hey guys, i'm struggling for a bit here. I need to...
# ask-community
f
Hey guys, i'm struggling for a bit here. I need to define a custom
context
value inside the flow run (So i can retrieve later via graphql query), the issue is (not all my flow will have this custom context value), for what i understand the context values is passed in
run()
call, is not possible to add/modify and retrieve this values later? If so, there a alternative i can use to get custom values from a flow?
a
@FuETL nice nick name šŸ™‚ Are you on Prefect Cloud? This would be a perfect use case for the KV Store, but it’s only available in Cloud.
To quote the docs from this page: ā€œCaveats to modifying Prefect-supplied context Since Prefect uses some context internally to track metadata during the flow and task run logic, modifying Prefect-supplied context keys can have unintended consequences. It is recommended to generally avoid overriding the key names described in the API documentation.ā€
f
hey @Anna Geller tks for the compliment 🤘 i'm using an local prefect cluster the KV store is only for Prefect Cloud? i did a poc using Parameter with default value and creating a function that do nothing but is seens so wrong doing this
Copy code
from prefect import Flow, Parameter, task
from prefect.executors import LocalDaskExecutor


@task()
def step_one(result_value):
    return result_value

@task()
def do_nothing(something):
    pass


with Flow(name="sample_flow") as flow:
    result_value = Parameter(name="result_value", required=True)
    value_that_want_retrieve = Parameter(name="value_that_want_retrieve", default="my value that i want to get later")
    step_one(result_value)
    do_nothing(value_that_want_retrieve)

if __name__ == "__main__":
    flow.executor = LocalDaskExecutor()
    flow.run(parameters={"result_value": "RESULT"})
then in graphql:
also @Anna Geller tks for this fast support!!
a
KV Store is only available when you run your flows with Cloud backend. But in case you don’t know yet, Prefect Cloud has a free tier allowing you to run 20,000 task runs each month completely for free, no credit card required to sign up.
here is how you could use it in a flow - I think KV Store is exactly what you try to do https://docs.prefect.io/orchestration/concepts/kv_store.html#using-key-value-pairs-in-flows
f
thank you i will take a look!!