question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

context's flow_id is None in Environment execute()

See original GitHub issue

Description

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:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
joeschmidcommented, May 1, 2020

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 and 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 make flow_id available in context. Thanks to @cicdw that PR now supports all agents.

1reaction
joeschmidcommented, Apr 30, 2020

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.)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found