Skip to content

Warn when Dag bundles are configured with the same source - #77375

Open
basantjamwal wants to merge 3 commits into
apache:mainfrom
basantjamwal:fix-duplicate-bundle-source-77241
Open

basantjamwal wants to merge 3 commits into
apache:mainfrom
basantjamwal:fix-duplicate-bundle-source-77241

Conversation

@basantjamwal

Copy link
Copy Markdown
Contributor

closes: #77241

DagBundlesManager.parse_config identifies bundles only by name, so two bundles that read the
same files (for example one Git repository over SSH and over HTTPS) are accepted without any
warning. Every file is then parsed twice, import errors are reported twice, and Dag ownership
switches between the two bundles on each parse loop.

This adds detection at config-parse time, as a warning only.

Changes

  • BaseDagBundle.source_key(**kwargs): new optional classmethod that says where a bundle reads
    its files from. It returns None by default, so existing and third-party bundles are unaffected.
  • LocalDagBundle returns its resolved directory.
  • GitDagBundle returns the repository (as host/path, without user, port or .git), the
    tracking ref and the subdir. SSH and HTTPS URLs of one repository give the same key. When
    repo_url is not in the kwargs (it comes from the connection) or is a local path, the key
    is None and the bundle is not compared.
  • DagBundlesManager logs one warning naming the bundles that share a source. The hook is
    called through getattr and wrapped in try/except, so an older provider or a faulty hook
    cannot break config parsing.
  • Docs: a note in dag-bundles.rst and a line in the duplicate dag_id FAQ entry.

Reproduction (before)
Two LocalDagBundles pointing at the same folder, on the apache/airflow Docker image: both
load without a warning, both parse the same files, and Duplicate dag_id detected alternates
existing_bundle=a/b every parse loop. A broken file is listed twice in
airflow dags list-import-errors.

Tests

  • test_local.py: key equal for equivalent paths, different for another path.
  • test_git.py: SSH, ssh://, HTTPS and HTTPS-with-credentials URLs give the same key; a different repository, ref or subdir gives a different key; no key without a remote URL; two end-to-end DagBundlesManager tests (warns for SSH + HTTPS of one repository, silent for different repositories).
  • Ran test_local.py, test_git.py (new tests) and test_dag_bundle_manager.py locally, plus ruff check and ruff format.

Left out on purpose

  • A reject_duplicate_bundle_sources option that turns the warning into an error (new config option, separate decision).
  • Nested subdirs of one repository (subdir="" and subdir="dags"), which can be intentional.

The warning is logged each time DagBundlesManager parses the config, so it appears in the log of each component that loads it.

URL test cases were informed by #77313 by @bnspopi, who offered them.

Was generative AI tooling used to co-author this PR?
  • Yes (Claude)

Generated-by: Claude following the guidelines

@meel-ayush

Copy link
Copy Markdown
Contributor

Good addition. Complementing the collection guard in #76556, caught three edge cases:

  1. git_conn_id not resolved: Bundles configured via connections omit repo_url from kwargs, so source_key returns None and misses duplicates. Needs fallback to BaseHook.get_connection(git_conn_id).host.
  2. Case-sensitive paths: Remote paths aren't lowercased, so github.com/Org/Repo and github.com/org/repo don't match.
  3. Provider test coupling: test_git.py imports core DagBundlesManager and asserts on caplog.text. That violates testing standards and breaks when testing providers against older Airflow cores.

Opened a PR against your branch with these fixes and tests: basantjamwal#1

Merging it will update this PR automatically.

@basantjamwal

Copy link
Copy Markdown
Contributor Author

Thanks @meel-ayush, I went through basantjamwal#1. I'll take (3) and move the manager tests into core's test_dag_bundle_manager.py, plus the lowercase-path change and the "Dag" wording, and I'll credit you for them. On (1), looking up the connection at config-parse time touches the DB or secrets backend in every component that loads the config, and the issue suggested skipping when repo_url isn't in the kwargs. I'd like maintainers' view before adding it.

@meel-ayush

Copy link
Copy Markdown
Contributor

Agreed on (1), dropped the connection lookup to keep config parsing strictly in-memory. Moved the manager tests into core's test_dag_bundle_manager.py alongside the path normalization.

Updated basantjamwal#1 so you can merge it directly.

Resolve connection IDs and case-insensitive paths in bundle source keys
@basantjamwal

Copy link
Copy Markdown
Contributor Author

Thanks @meel-ayush, merged basantjamwal#1. Agreed on keeping config parsing in-memory, so the connection lookup stays out. The manager tests now live in core's test_dag_bundle_manager.py.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants