Skip to content

Unable to add custom values to prefect.context #3224

Answered by cicdw
sierrezinal asked this question in Q&A
Discussion options

You must be logged in to vote

If you are using flow.run, the correct way to specify new context key / value pairs is via the context keyword argument:

flow.run(context={'jobid': jobid})

If you are using Prefect Cloud or Server, the API allows you to provide new key / value pairs for each ad-hoc run.

Also, it appears that you are using context incorrectly. You should never place tasks in context; if you are interested in passing data from one task to another, you should do so explicitly:

with Flow("myflow", schedule=schedule) as flow:
    jobid = Parameter("jobid")
    another_task(jobid=jobid) # will pass the jobid value to the task

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sierrezinal
Comment options

Answer selected by sierrezinal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants