Keep ZIP-archived Dags active when dag_discovery_safe_mode is False - #68518
Keep ZIP-archived Dags active when dag_discovery_safe_mode is False#68518Vamsi-klu wants to merge 3 commits into
Conversation
2e35a34 to
11741f4
Compare
11741f4 to
942843f
Compare
942843f to
13d95bc
Compare
13d95bc to
78350c2
Compare
78350c2 to
a9790a8
Compare
|
Rebased this PR onto current upstream/main, resolved the Dag processor manager conflict, and marked it ready for review. The conflict resolution keeps upstream lazy execution API initialization and applies dag_discovery_safe_mode consistently to both bundle file discovery and ZIP-member observation. Validation run:
PR is now mergeable; required review/checks remain. Drafted-by: Codex (GPT-5) |
a9790a8 to
2283633
Compare
There was a problem hiding this comment.
Nice catch fixing both spots here. One gap: there's no regression test for the _find_files_in_bundle fix, only for _get_observed_filelocs. Could you add a parametrized test mirroring the existing one, asserting a keyword-less .py file is included/excluded based on dag_discovery_safe_mode? Otherwise a future change could silently reintroduce that half of the bug.
The Dag file processor parsed and activated keyword-less Dags inside ZIP archives but then immediately deactivated them, because the scan that decides which files still exist ignored dag_discovery_safe_mode and always applied the airflow/dag keyword heuristic. Resolve the setting once and use it consistently for discovery and the deactivation scan, and log the effective value so a misconfigured processor is diagnosable. closes: apache#66104
The file-discovery and observed-file paths must both honor safe mode so wrapped Dag files are not silently skipped by a future regression.
2283633 to
48af3f7
Compare
|
Added the parameterized |
Vamsi-klu
left a comment
There was a problem hiding this comment.
@vatsrahul1001 Addressed your feedback: added parametrized test_find_files_in_bundle_respects_dag_discovery_safe_mode in 48af3f7 (safe_mode on/off for keyword-less .py discovery). Ready for another look.
|
Good catch, thanks. That test is already on the current head (48af3f7): Drafted-by: Claude Code (Fable 5); reviewed by @Vamsi-klu before posting |
|
LGTM!, can be merged after code owner review @ephraimbuddy @jedcunningham |
ephraimbuddy
left a comment
There was a problem hiding this comment.
LGTM
The tests bypass the config wiring. Can you make it use it?
| """Resolved once per process so file discovery and the deactivation scan use the same value. | ||
|
|
||
| When ``False`` the keyword heuristic is bypassed and every Python file is scanned -- this must | ||
| apply consistently to discovery (:meth:`_find_files_in_bundle`) and to the set of observed | ||
| filelocs (:meth:`_get_observed_filelocs`); otherwise freshly-parsed keyword-less Dags are | ||
| deactivated right after being parsed (issue #66104).""" |
There was a problem hiding this comment.
| """Resolved once per process so file discovery and the deactivation scan use the same value. | |
| When ``False`` the keyword heuristic is bypassed and every Python file is scanned -- this must | |
| apply consistently to discovery (:meth:`_find_files_in_bundle`) and to the set of observed | |
| filelocs (:meth:`_get_observed_filelocs`); otherwise freshly-parsed keyword-less Dags are | |
| deactivated right after being parsed (issue #66104).""" | |
| """Resolved once per process so file discovery and the deactivation scan use the same value.""" |
This should just be one line comment
There was a problem hiding this comment.
Done in a45c514, collapsed to the suggested one-line docstring.
Drafted-by: Claude Code (Fable 5); reviewed by @Vamsi-klu before posting
There was a problem hiding this comment.
Good call, done in a45c514. It's just the one-liner you suggested now.
Drafted-by: Claude Code (Fable 5); reviewed by @Vamsi-klu before posting
| ``with_keywords.py`` contains the ``airflow``/``dag`` strings the safe-mode heuristic looks | ||
| for. ``no_keywords.py`` mimics a custom wrapper whose source contains neither ``airflow`` nor | ||
| ``dag``/``asset`` -- exactly the case ``dag_discovery_safe_mode=False`` exists to support | ||
| (issue #66104). |
There was a problem hiding this comment.
Issue numbers shouldn't be in codes except if it's a todo
There was a problem hiding this comment.
Dropped it in a45c514. While I was at it I noticed one more #66104 reference in another test docstring in the same file, so I cleaned that one up too. None left now.
Drafted-by: Claude Code (Fable 5); reviewed by @Vamsi-klu before posting
| if might_contain_dag(info.filename, True, z): | ||
| # Must use the same safe_mode as discovery/parsing: with a hardcoded True a | ||
| # keyword-less zip member parsed under safe_mode=False would be absent here and | ||
| # then deactivated immediately after being parsed (issue #66104). |
There was a problem hiding this comment.
Remove issue number and make this comment really short e.g use configured discovery safe mode
There was a problem hiding this comment.
Done, went with your wording in a45c514.
Drafted-by: Claude Code (Fable 5); reviewed by @Vamsi-klu before posting
Review asked for one-line comments and no issue numbers in code, since the PR link already carries that context.
Fixes #66104.
When
[core] dag_discovery_safe_modeisFalse, Dags defined in ZIP archives whose source does not contain theairflow/dagkeywords were parsed and activated by the Dag file processor but then immediately deactivated on the next scan._get_observed_filelocsexpanded ZIP members with a hardcodedsafe_mode=True, so keyword-less members were absent from the observed set anddeactivate_deleted_dagsmarked them stale.Changes:
dag_discovery_safe_modeonce onDagFileProcessorManagerand use it for both file discovery (_find_files_in_bundle) and the observed-filelocs scan (_get_observed_filelocs), fixing the hardcodedTrue.dag_discovery_safe_modeper bundle. In separate-process deployments (Helm/OpenShift) the flag must be set on the dag-processor and the component restarted; otherwise Dags appear afterairflow dags reserializeand disappear on the next scan (the plain-.py symptom in the issue). The log makes that misconfiguration diagnosable.Tested: new parametrized regression test
test_get_observed_filelocs_respects_dag_discovery_safe_mode(keyword-less ZIP member is observed when safe_mode is False, filtered when True).Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 4.8) following the guidelines
Important
🛠️ Maintainer triage note for @Vamsi-klu · by
@potiuk· 2026-07-02 17:46 UTCHelpful heads-up from the maintainers — please address before this PR can be reviewed (see the Pull Request quality criteria):
main. Please rebase onto the latestmainand resolve them.The ball is in your court — you've been assigned to this PR. Fix the above, then mark it Ready for review.
Automated triage — may be imperfect; a maintainer takes the next look.