tony
10/10/2025, 12:38 PMMarvin
10/10/2025, 12:38 PMMarvin
10/10/2025, 12:45 PMretries>0
, remove them to prevent automatic retries.
- Flow runs API ref (for context on run state/attempts): Flow runs API
- Add a defensive guard in your flow (optional):
- If you want to hard-block restarts at runtime, you can check the run count and fail early if it’s >1.
- Example:
from prefect import flow, context
@flow
def my_flow():
ctx = context.get_run_context()
run_count = getattr(ctx.flow_run, "run_count", 1)
if run_count > 1:
raise RuntimeError(f"Restarts disabled for this flow run (run_count={run_count}).")
# ...rest of your flow...
Questions to help me tailor this:
- Do you want to prevent manual restarts by teammates in the UI, or did an automation/CI trigger the second attempt?
- Are you using Prefect Cloud (RBAC available) or open-source Server?tony
10/10/2025, 12:58 PMMarvin
10/10/2025, 12:58 PMMarvin
10/10/2025, 1:00 PMimport asyncio
from prefect.client.orchestration import get_client
async def show(flow_run_id: str):
async with get_client() as client:
fr = await client.read_flow_run(flow_run_id)
# max_retries lives on the run's policy
print("max_retries:", fr.empirical_policy.max_retries)
print("retry_delay_seconds:", fr.empirical_policy.retry_delay_seconds)
asyncio.run(show("<your_flow_run_id>"))
Docs: Flow runs API
- Check at runtime from inside the flow
from prefect import flow, context, get_run_logger
@flow
def my_flow():
logger = get_run_logger()
ctx = context.get_run_context()
policy = ctx.flow_run.empirical_policy
<http://logger.info|logger.info>(f"max_retries={policy.max_retries}, retry_delay_seconds={policy.retry_delay_seconds}")
- Check the flow’s code-defined retries (what the decorator sets)
# if you have the Flow object imported
from my_module import my_flow
print("flow.retries:", my_flow.retries)
Note: The decorator parameter is `retries`; the server computes max_retries
for each run from that.
If you share a flow_run_id, I can run the client snippet for you (or adapt it) to confirm your current max_retries.