Nils
01/20/2025, 9:34 AMMarvin
01/20/2025, 9:34 AMflow_run_id
from the task's context. Here’s a concise way to do it:
1. Import the necessary context functions from Prefect.
2. Use the context to access the flow_run_id
.
Here's a simple example:
python
from prefect import task
from prefect.context import FlowRunContext
@task
def get_parent_flow_run_id():
flow_run_context = FlowRunContext.get()
if flow_run_context:
parent_flow_run_id = flow_run_context.flow_run.id
print(f"Parent Flow Run ID: {parent_flow_run_id}")
else:
print("No flow run context available")
In this example, FlowRunContext.get()
is used to access the flow run context, and from there, you can retrieve the flow_run.id
.
For more details, you can explore the documentation:
- Prefect 3.x Task Run Limits
- Prefect 3.x Write Flows
If you have any further questions or need more specific guidance, feel free to ask.