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.