Repository navigation
Conversation
There was a problem hiding this comment.
We also have #71425 to address the same issue.
Edit: #71425 isn't solving that issue.
@ephraimbuddy @dstandish wdyt?
This doesn't solve the contract problem mentioned in the other PR but can help sove the immediate reported issues with minimal effort. While we figure out the interface we want.
pierrejeambrun
left a comment
There was a problem hiding this comment.
A few nits, looking good to me.
|
Added coverage for a full After every TI is cleared, current tasks are all on latest and the older version only remains on TIH. @ephraimbuddy this should be ready for another look. |
|
@ephraimbuddy could you please take another look at this ? |
|
@ephraimbuddy this should be ready for another look. |
|
The GET test now asserts serialization leaves TI/TIH collections unloaded on a bundled run with history, so it fails if the prefetch is dropped. @ephraimbuddy this should be ready for another look. |
c3d7810 to
9c4a219
Compare
|
@ephraimbuddy this should be ready for another look. |
6bd4fbe to
da51f3c
Compare
|
Rebased onto current The query uses @ephraimbuddy would you mind another look? |
Stop special-casing bundle-versioned runs through created_dag_version_id. Always derive versions from the run's TaskInstance / history rows so mixed versions after a partial clear are reported correctly. Closes apache#71454 Signed-off-by: Digvijay <[email protected]>
attach_dag_versions_to_runs previously skipped runs with bundle_version, assuming dag_versions used created_dag_version. After removing that shortcut, prefetch all runs so Grid/UI keeps the lightweight path and still sees mixed TI versions. Signed-off-by: Digvijay <[email protected]>
Shorten the dag_versions comment, drop the issue number from the test, and name the case for bundled DAGs. Signed-off-by: Digvijay <[email protected]>
A full clear moves every current TI to latest, so the older version only remains on TIH. Cover that path and keep prefetch from skipping bundle-versioned runs. Signed-off-by: Digvijay <[email protected]>
get_dag_run() skipped attach_dag_versions_to_runs, so opening a large mapped run materialized every TI/TIH row just to return versions. Signed-off-by: Digvijay <[email protected]>
Query count stayed flat even when each query loaded every TI/TIH row. Serialize a bundle-versioned run with history and assert those collections stay unloaded. Signed-off-by: Digvijay <[email protected]>
A note-only update still serializes dag_versions, so without the DISTINCT helper it walks every TI/TIH row. Reload tests by primary key because run_id is only unique within a Dag. Signed-off-by: Digvijay <[email protected]>
Session-attached runs now use one DISTINCT query over current and archived attempts, so clear, trigger, and other single-run routes serialize versions without walking TI collections. include_all_attempts=True is required after attempt archiving so a full run_on_latest_version clear still surfaces the older version. Signed-off-by: Digvijay <[email protected]>
da51f3c to
9e1b3ce
Compare
Annotate fetch_dag_versions_for_runs, give the transient DagVersion a real id, and expire TI collections before asserting serialization so the check measures the DISTINCT fallback rather than leftover identity-map state from clear. Signed-off-by: Digvijay <[email protected]>
ephraimbuddy
left a comment
There was a problem hiding this comment.
Looks good. Moving the lookup into the property covers the clear routes, and include_all_attempts=True keeps the full-clear case. A few small comments inline.
Collapse the version fetch into one query, restore the lighter GET load, and keep only the response checks that still cover archived attempts. Signed-off-by: Digvijay <[email protected]>
|
Addressed the latest review:
@ephraimbuddy this should be ready for another look. |
Bulk clear serializes dag_versions, so attach the batch prefetch before building the response. Runs with no attempt version report created_dag_version. Signed-off-by: Digvijay <[email protected]>
6fe210f to
e43dcdb
Compare
| # Transient run (e.g. built in memory in tests): use the in-memory relationships. | ||
| versions = dict.fromkeys(list(self._historical_dag_versions) + list(self._ti_dag_versions)) | ||
| result = sorted((dv for dv in versions if dv is not None), key=lambda dv: dv.id) | ||
| if not result and self.created_dag_version is not None: |
There was a problem hiding this comment.
When does this fire? Runs from before Dag versioning have created_dag_version_id NULL too, since 0047 adds the column without a backfill, so the docstring example never reaches it. Runs created since then get a version on their TIs at creation. This also changes unpinned runs, which returned [] here before. If it's for runs whose TIs were cleaned up, please say that in the docstring; otherwise I'd drop it.
Fix
DagRun.dag_versionssilently dropping older versions still in use after arun_on_latest_versionclear.For bundle-versioned runs the property previously returned only
created_dag_version. Clearing withrun_on_latest_version=Truebumps that pointer to latest while uncleared TaskInstances or archived attempts keep the olderdag_version_id, so the Grid UI could show a single version chip while tasks were still executing under mixed versions.Changes
DagRun.dag_versionsnow derives versions from a single DISTINCT query over current and archived attempts (include_all_attempts=True) whenever the run is attached to a session. New routes get this automatically; no per-route helper call is needed.attach_dag_versions_to_runsis the batch form of the same query, used by the list and grid endpoints.get_dag_runandpatch_dag_runno longer call it. Bulk clear calls it before serializing the cleared runs.bundle_versionshortcut that returned onlycreated_dag_versionis removed, so a run cleared withrun_on_latest_version=Truereports every version still present on its attempts.created_dag_versionis used only when no attempt carries a version.TaskInstanceHistoryremoved).closes: #71454
Testing
uv run --project airflow-core pytest airflow-core/tests/unit/models/test_dagrun.py -k "dag_versions" -quv run --project airflow-core pytest airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_run.py -k "unloaded or bundle_version or dag_versions" -quv run --project airflow-core pytest airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_grid.py -qWas generative AI tooling used to co-author this PR?
Generated-by: Cursor