<@ULVA73B9P> if I redeploy a flow, the scheduled r...
# ask-marvin
l
@Marvin if I redeploy a flow, the scheduled runs before the redeploy will execute in which version?
m
thought for 352.6 seconds
Short answer: they’ll run with the latest deployment version you just deployed. Details (Prefect 3.x): - When you redeploy (upsert) an existing deployment, Prefect deletes any future scheduled runs for that deployment and the scheduler recreates them under the new active deployment version. So upcoming runs will execute with the new code/config. - Flow runs reference a deployment ID, not a specific version. At execution time, workers fetch the current active version of that deployment, so even ad‑hoc/manual runs created earlier will use the active version when they start. - If instead you created a brand-new deployment (different name), the old deployment’s schedule and runs are unaffected and will continue to use the old code until you pause/disable it. If you need to keep scheduled runs on the old code, either: - Roll back to a previous deployment version, or - Keep the old deployment active and schedule the new version under a different deployment name. References: - Deployment versioning in Prefect 3 - Schedules concept
l
Its possible to see in which version the flow runned ?
@Marvin Its possible to see in which version the flow runned ?
m
thought for 436.2 seconds
Short answer: there isn’t a “deployment_version” field on a flow run. Runs are linked to a deployment by
deployment_id
, and the deployment holds the version info. Ways to see or record it (Prefect 3.x): - During the run (recommended): read and log the deployment version from the runtime context.
Copy code
from prefect import flow, get_run_logger
from prefect.runtime.deployment import version as deployment_version

@flow
def my_flow():
    logger = get_run_logger()
    <http://logger.info|logger.info>(f"Deployment version: {deployment_version()}")
You can also persist it as an artifact:
Copy code
from prefect.artifacts import create_markdown_artifact
create_markdown_artifact(key="deployment_version", markdown=f"Version: {deployment_version()}")
- After the fact: 1) Get the run details to see its `deployment_id`:
Copy code
prefect flow-run inspect <flow-run-id>
2) Inspect the deployment or check its version history in the UI. The CLI shows the current version:
Copy code
prefect deployment inspect "<flow_name>/<deployment_name>"
For historical versions and rollbacks, use the UI’s Deployment “Versions” view to correlate the run’s start time with the active version at that time. Notes: - Don’t confuse
flow_version
(set on the
@flow(version=...)
) with the deployment version—they’re different. - If you need an authoritative record per run, logging or writing an artifact with
prefect.runtime.deployment.version()
is the most reliable. References: - Deployment versioning - Runtime context (prefect.runtime) - CLI: flow-run inspect - CLI: deployment inspect