Repository navigation
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
e68ed8b to
b1638fa
Compare
SameerMesiah97
left a comment
There was a problem hiding this comment.
I would want a maintainer to weigh in here but it looks fine to me. Just one nit. And CI needs to be triggered.
e84a967 to
c7d9ab0
Compare
c7d9ab0 to
5b30edd
Compare
|
@SameerMesiah97 Thank you, I didn't know who to ask! |
The regex branch of `get_dags` ignored `from_db=True` and built a
`BundleDagBag` off disk, returning SDK `DAG` objects. `task_clear` then
calls `SerializedDAG.clear_dags`, which calls `.clear()` on each — a
method that only exists on `SerializedDAG`. Result:
AttributeError: 'DAG' object has no attribute 'clear'
The non-regex branch was fixed in apache#63827 (closes apache#63817) but the regex
path was left untouched and untested.
This change honors `from_db=True` in the regex branch too, querying
`SerializedDagModel.read_all_dags()` and regex-filtering DAG IDs in
Python. The previous bundle-walking path is preserved for callers that
don't pass `from_db`. Also switches the "not found" raise from the
generic `AirflowException` to `DagNotFound`.
related: apache#63817
5b30edd to
c261fef
Compare
|
@potiuk I rebased since it's been 2 weeks, which unfortunately resets the CI tag |
|
@potiuk Rebased in the hope that whatever was failing CI (it was a static check complaining about a file I hadn't touched) has been addressed in the interim :) |
potiuk
left a comment
There was a problem hiding this comment.
Thanks for chasing this down — the diagnosis is right: the regex branch was handing back SDK DAG objects while SerializedDAG.clear_dags needs .clear(), and DagNotFound is the correct exception to raise here rather than AirflowException.
One blocking issue though: the new branch drops the bundle_names filter entirely, which for a destructive command like tasks clear widens the blast radius silently. Details inline, plus a note on loading every serialized Dag into memory and one on the test assertions.
Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting
| return [get_db_dag(bundle_names=bundle_names, dag_id=dag_id)] | ||
| return [get_bagged_dag(bundle_names=bundle_names, dag_id=dag_id)] | ||
|
|
||
| if from_db: |
There was a problem hiding this comment.
This branch returns before bundle_names is ever consulted, so --bundle-name is silently ignored on the regex path.
Both other paths honour it: the non-regex from_db branch passes it to get_db_dag(bundle_names=..., dag_id=...), and the existing regex branch below iterates bundle_names first and only falls back to all bundles when nothing matched. As written, airflow tasks clear --bundle-name X -R <pattern> would clear matching Dags from every bundle — a silent widening on a destructive command.
Please filter by bundle here too, mirroring the fallback behaviour of the branch below.
Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting
|
|
||
| matched_dags = [ | ||
| dag | ||
| for dag_id_key, dag in SerializedDagModel.read_all_dags().items() |
There was a problem hiding this comment.
read_all_dags() deserializes every Dag in the deployment to then regex-filter them in Python. On a large instance that is a lot of memory and CPU for a CLI call that usually matches a handful of Dags.
Since the filter is a plain re.search against dag_id, this could be pushed into SQL — or at minimum select the ids first and only deserialize the matches.
Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting
| dags = get_dags(bundle_names=None, dag_id="example_python_operator", use_regex=True, from_db=True) | ||
| assert dags | ||
| for dag in dags: | ||
| assert hasattr(dag, "clear"), f"{type(dag).__name__} is missing .clear()" |
There was a problem hiding this comment.
hasattr(dag, "clear") is a weak assertion — it passes for anything that happens to expose a clear attribute, including a plain dict. Since the whole point is the concrete type, assert isinstance(dag, SerializedDAG) states the actual contract.
Separately, test_task_clear_dag_regex_does_not_attribute_error below runs a real tasks clear -y against example_python_operator — worth confirming it's covered by the DB-test markers so it isn't mutating state shared with other tests.
Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
airflow tasks clear --dag-regex <pattern>crashes withAttributeError: 'DAG' object has no attribute 'clear'whenever the regex matches one or more Dags. The non-regex form works.Reproduction
Root cause
task_clearcallsget_dags(..., from_db=True)expectingSerializedDAGinstances, because that's the typeSerializedDAG.clear_dagsiterates over (it calls.clear()on each, which only exists onSerializedDAG, not on the SDKDAGreturned byBundleDagBag). See the existing comment attask_command.py:504:But in
utils/cli.py,get_dagsonly honorsfrom_dbin the non-regex branch:The
from_dbparameter was added in #48471 (closes #48430), which only plumbed it through the non-regex branch. Issue #63817 reported this sameAttributeErrorfor the non-regex path; #63827 fixed it by swappingget_dag_by_file_location→get_db_dag. The regex path was left in the original broken state, and no test guarded it.Fix
In
get_dags, whenuse_regex=Trueandfrom_db=True, querySerializedDagModel.read_all_dags()and regex-filter the Dag IDs. The non-regex path is unchanged. The original bundle-walking path is preserved for callers that don't passfrom_db(e.g.dags trigger -R,dags pause -R).Also switches the "not found" raise from the generic
AirflowExceptiontoDagNotFoundper the coding standards (prefer specific exceptions).Side benefit: the previous bundle-walking path breaks out of the loop after the first bundle with any matches (
utils/cli.py:343-344), so regex matches spanning multiple bundles were silently truncated. Querying the serialized Dag table sees all Dags regardless of bundle.Tests
test_task_clear_with_dag_regex_returns_serialized_dags— unit-level: assertsget_dags(use_regex=True, from_db=True)returns objects with.clear().test_task_clear_dag_regex_does_not_attribute_error— end-to-end regression test: invokestask_command.task_clearwith-Rand asserts it completes without the originalAttributeError. Verified to fail with the exact pre-fix traceback when thecli.pychange is reverted.related: #63817
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.7) following the guidelines
Important
🛠️ Maintainer triage note for @jni-bot · by
@potiuk· 2026-06-18 13:57 UTCPaused pending your next update — this PR has been inactive for ~30 days, so it's been moved to draft to keep the review queue clear:
main, address any new failures, and mark it Ready for review when you pick it back up — no rush.The ball is in your court — you've been assigned to this PR.
Automated triage — may be imperfect; a maintainer takes the next look.