basantjamwal opened a new pull request, #77375:
URL: https://github.com/apache/airflow/pull/77375
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 `LocalDagBundle`s 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?
- [x] Yes (Claude)
Generated-by: Claude following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
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]