Theom
03/12/2026, 10:59 AMMarvin
03/12/2026, 11:00 AMMarvin
03/12/2026, 11:04 AMprefect.runtime.flow_run.flow_version.
- Source references:
- Flow decorator (shows the version parameter): https://github.com/PrefectHQ/prefect/blob/main/src/prefect/flows.py
- Runtime fields (includes flow_version): https://github.com/PrefectHQ/prefect/blob/main/src/prefect/runtime/flow_run.py
- deployment_version
- What it is: A string on the Deployment object that’s captured onto each Flow Run launched by that deployment as deployment_version.
- How it’s set:
- If you pass version to .deploy(...) (or .to_deployment(...)), that value is used.
- If you don’t pass it, Prefect sets the deployment’s version to the flow’s current version (i.e., deployment_version defaults to flow_version at deploy time).
- If the flow had no version, the deployment_version will be None unless you set it.
- Where you’ll see it: On runs started by that deployment; in Prefect Cloud, you also get deployment version history with rollbacks/promotions.
- Source reference (defaulting behavior in runner): https://github.com/PrefectHQ/prefect/blob/main/src/prefect/deployments/runner.py
Behavior notes
- Runs launched by a deployment record both values:
- flow_run.flow_version = the flow’s version at run creation
- flow_run.deployment_version = the deployment’s version
- Ad-hoc runs (no deployment) will have flow_version set (if available) and deployment_version = None.
- There is no bidirectional fallback at run time: deployment_version does not become flow_version on the run unless it was set on the deployment; flow_version never defaults to deployment_version.
Recommendations
- Prefer setting both explicitly and independently:
- In code, set @flow(version="1.2.3") to track code lineage across all runs.
- In deployments, set version="deploy-2026-03-12" (or similar) when you change deployment config (work pool, job variables, entrypoint, default parameters, etc.).
- If you only pick one:
- Use flow_version to attribute runs to specific code (debugging, reproducibility).
- Use deployment_version when you operationally manage promotion/rollback of deployment configs (especially in Cloud).
Example
from prefect import flow
@flow(version="1.2.3") # flow_version
def my_flow():
...
# Deployment version is separate and optional
my_flow.deploy(
name="prod",
version="2026-03-12-a", # deployment_version
work_pool_name="prod-pool"
)
Where to read more
- Flow decorator/API (version param): https://github.com/PrefectHQ/prefect/blob/main/src/prefect/flows.py
- Runtime access to run fields: https://github.com/PrefectHQ/prefect/blob/main/src/prefect/runtime/flow_run.py
- Deployment runner (version defaulting logic): https://github.com/PrefectHQ/prefect/blob/main/src/prefect/deployments/runner.py
- Deployments overview (docs): https://docs.prefect.io/latest/deploy/ (see versioning/updates for Prefect Cloud)