context's flow_id is None in Environment execute()
See original GitHub issueDescription
During testing of DaskCloudProviderEnvironment
we noticed that prefect.context.get("flow_id")
returns None in our execute() method. prefect.context.get("flow_run_id")
does correctly return the flow run id and we are able to retrieve the flow_id with essentially client.get_flow_run_info(flow_run_id).flow_id
Expected Behavior
flow_id should be available in context inside an Environment’s execute() method.
Reproduction
def execute(self, storage: "Storage", flow_location: str, **kwargs: Any) -> None:
flow_id = prefect.context.get("flow_id")
if not flow_id: # We've observed cases where flow_id is None
if not flow_run_info:
client = Client()
flow_run_info = client.get_flow_run_info(flow_run_id)
flow_id = flow_run_info.flow_id
Environment
Docker storage with the Fargate agent. (Agent is running Fargate tasks for the flow runs.)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Using Contexts
Contexts provide a mechanism for securing and sharing environment variables across projects. The environment variables are defined as name/value pairs and ...
Read more >ExecutionEnvironment (Flink : 1.17-SNAPSHOT API)
Creates an execution environment that represents the context in which the program is currently executed. String · getExecutionPlan(). Creates the plan with ...
Read more >Troubleshoot issues when passing environment variables ...
Your Amazon ECS task execution role doesn't have the required IAM permissions. If you're using environment variables inside Parameter Store ...
Read more >Renewable Energy and Electricity
There is unprecedented interest in renewable energy, as sources of sustainable energy, particularly solar and wind energy, which provide electricity with ...
Read more >PeopleSoft PeopleTools - Get Started
Note: You can configure context-sensitive help to always display help for the ... Start here to find all of the latest resources for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ended up making a small, separate PR for this: https://github.com/PrefectHQ/prefect/pull/2461 since it could use a bit of explanation…
For the Docker, Fargate, Local, & Nomad agents it was extremely simple to add this. For the Kubernetes agent andThanks to @cicdw that PR now supports all agents.FargateTaskEnvironment
this wasn’t readily available. We could obviously add a GraphQL query for these if we want to keep the behavior uniform, i.e. for all agents/environments to makeflow_id
available in context.Hi @lauralorenz, that makes total sense. I’ll plan to include it! Given that I’m in there anyway it’ll be easy to test. (And I’ll back out my funky logic to workaround not having flow_id.)