<@ULVA73B9P> It's possible to access the current r...
# ask-marvin
b
@Marvin It's possible to access the current run id with context.get("flow_run_id"), correct? What happens if this flow is retried, will it get a new run-id? And if so, can I somehow retrieve the old run id from the cache again?
m
In Prefect 3.x, you can access the current flow run ID using
prefect.context.get_run_context()
, which provides access to runtime information, including the flow run ID. Here's the relevant documentation link. Regarding retries, when a flow is retried, a new flow run ID is created. However, for tasks, a new task run is not created when a task is retried; instead, a new state is added to the state history of the original task run. More on this can be found in the task retry documentation. As for retrieving the old run ID, it appears there's no direct mechanism to fetch previous flow run IDs from within the Prefect context itself. However, if you have implemented caching policies or custom logging, you might have stored these IDs externally. You can refer to the cache policies code for more details on how cache keys are computed, which might give you insights into custom storage solutions. If you have further specific requirements or setups, feel free to share them, and I can assist you more precisely.
n
or runtime module
Copy code
#[1]
from prefect import flow, runtime

#[2]
@flow(retries=2)
def f():
    print(runtime.flow_run.id)
    raise ValueError
🙏 1
marvin is wrong, its the same id
b
Ah, awesome! Thanks 🙂