Copilot commented on code in PR #68339:
URL: https://github.com/apache/airflow/pull/68339#discussion_r3388744986
##########
airflow-core/src/airflow/utils/db_cleanup.py:
##########
@@ -92,6 +98,8 @@ class _TableConfig:
# Relying on automation here would increase complexity and reduce
maintainability.
dependent_tables: list[str] | None = None
extra_filters: list[Any] | None = None
+ skip_if_referenced: list[tuple[str, str]] | None = None
+ referenced_pk_column: str = "id"
def __post_init__(self):
self.recency_column = column(self.recency_column_name)
Review Comment:
`skip_if_referenced` relies on `referenced_pk_column` being present on
`orm_model` (via `extra_columns`), otherwise `_build_query()` will raise a
`KeyError` when it evaluates `base_table.c[referenced_pk_column]`. Since this
is a new generic option, it should fail fast with a clear error if
misconfigured.
##########
airflow-core/tests/unit/utils/test_db_cleanup.py:
##########
@@ -474,6 +474,78 @@ def test__skip_archive(self, skip_archive,
expected_archives):
assert session.scalar(select(func.count()).select_from(model)) == 5
assert len(_get_archived_table_names(["dag_run"], session)) ==
expected_archives
+ def test_dag_version_cleanup_skips_versions_pinned_by_task_instance(self):
+ """Regression test for #66177.
+
+ ``task_instance.dag_version_id`` is ``ON DELETE RESTRICT``, so a
``dag_version`` still
+ referenced by a task instance cannot be deleted — attempting it fails
the FK and, on
+ MySQL, hangs the cleanup command on metadata locks. Cleanup must skip
those rows while
+ still pruning genuinely orphaned old versions.
+ """
Review Comment:
Test docstrings should describe behavior without embedding issue numbers
(they go stale and are less searchable than descriptive text). Consider
rewording this docstring to omit `#66177` while keeping the behavioral intent.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]