takayoshi-makabe commented on code in PR #68791:
URL: https://github.com/apache/airflow/pull/68791#discussion_r3510253022
##########
airflow-core/src/airflow/dag_processing/collection.py:
##########
@@ -325,6 +325,59 @@ def _sync_dag_perms(dag: LazyDeserializedDAG, session:
Session):
security_manager.sync_perm_for_dag(dag_id, dag.access_control)
+def _build_duplicate_dag_id_warnings(
+ dags: Collection[LazyDeserializedDAG],
+ bundle_name: str,
+ session: Session,
+) -> set[DagWarning]:
+ """
+ Detect dag_ids that are defined in multiple files and return DagWarning
objects for each.
+
+ A warning is emitted whenever the incoming file differs from the file
already recorded in
+ DagModel. This covers both accidental duplicates and file renames while
leaving the final
+ interpretation to the user.
+ """
+ dag_by_id = {dag.dag_id: dag for dag in dags}
+ if not dag_by_id:
+ return set()
+
+ existing_rows = session.execute(
+ select(DagModel.dag_id, DagModel.bundle_name,
DagModel.relative_fileloc).where(
+ DagModel.dag_id.in_(dag_by_id),
+ DagModel.is_stale == false(),
+ )
+ )
+
+ warnings: set[DagWarning] = set()
+ for existing in existing_rows:
+ dag = dag_by_id[existing.dag_id]
+ if bundle_name == existing.bundle_name and dag.relative_fileloc ==
existing.relative_fileloc:
+ continue
+
+ message = (
+ f"dag_id '{dag.dag_id}' is now served from
'{dag.relative_fileloc}' "
+ f"(bundle: '{bundle_name}'), previously registered from
'{existing.relative_fileloc}' "
+ f"(bundle: '{existing.bundle_name}'). "
+ f"If '{existing.relative_fileloc}' was renamed or moved, this
notice will clear on "
+ "the next parse cycle once the old file is no longer observed. "
+ f"If both files coexist with the same dag_id, rename one of them
to avoid "
+ "non-deterministic behavior."
+ )
Review Comment:
fix
https://github.com/apache/airflow/pull/68791/commits/6120028321a27bb9ec7e982114df2d328a83d3ff
--
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]