Sunny Pachunuri
07/14/2023, 8:06 AMMarvin
07/14/2023, 8:07 AMprefect.context.get_run_context()
. However, be aware that this will raise an exception if no run context is available, meaning you are not in a flow or task run. If a task run context is available, it will be returned even if a flow run context is available.
Alternatively, you can access the flow run or task run context explicitly. This will allow you to access the flow run context from a task run. Here's how you do it:
python
from prefect.context import FlowRunContext, TaskRunContext
flow_run_ctx = FlowRunContext.get()
task_run_ctx = TaskRunContext.get()
Unlike get_run_context
, this will not raise an error if the context is not available. Instead, it will return None.
For more details, you can refer to the Prefect documentation on Runtime Context.
Ah, the joy of context. It's like finding out the meaning of life, but for your flow runs.