Vamsi-klu commented on code in PR #68518:
URL: https://github.com/apache/airflow/pull/68518#discussion_r3709998706


##########
airflow-core/src/airflow/dag_processing/manager.py:
##########
@@ -299,6 +299,16 @@ class DagFileProcessorManager(LoggingMixin):
         factory=_config_get_factory("dag_processor", "file_parsing_sort_mode")
     )
 
+    dag_discovery_safe_mode: bool = attrs.field(
+        factory=_config_bool_factory("core", "DAG_DISCOVERY_SAFE_MODE")
+    )
+    """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)."""

Review Comment:
   Good call, done in a45c514830. It's just the one-liner you suggested now.
   
   ---
   Drafted-by: Claude Code (Fable 5); reviewed by @Vamsi-klu before posting



##########
airflow-core/src/airflow/dag_processing/manager.py:
##########
@@ -925,8 +935,19 @@ def _find_files_in_bundle(self, bundle: BaseDagBundle) -> 
list[Path]:
         """Get relative paths for dag files from bundle dir."""
         # Build up a list of Python files that could contain DAGs
         self.log.info("Searching for files in %s at %s", bundle.name, 
bundle.path)
-        rel_paths = [Path(x).relative_to(bundle.path) for x in 
list_py_file_paths(bundle.path)]
-        self.log.info("Found %s files for bundle %s", len(rel_paths), 
bundle.name)
+        rel_paths = [
+            Path(x).relative_to(bundle.path)
+            for x in list_py_file_paths(bundle.path, 
safe_mode=self.dag_discovery_safe_mode)
+        ]
+        # Logging the effective safe_mode makes a misconfigured dag-processor 
diagnosable: a
+        # component left at the default safe_mode=True silently skips 
keyword-less files even
+        # when the deployment set core.dag_discovery_safe_mode=False elsewhere 
(issue #66104).

Review Comment:
   You're right, the log line already says everything that comment was trying 
to say. Removed in a45c514830.
   
   ---
   Drafted-by: Claude Code (Fable 5); reviewed by @Vamsi-klu before posting



##########
airflow-core/tests/unit/dag_processing/test_manager.py:
##########
@@ -157,6 +157,41 @@ def 
_create_zip_bundle_with_valid_and_broken_dags(zip_path: Path) -> None:
         )
 
 
+def _create_zip_bundle_with_keywordless_dag(zip_path: Path) -> None:
+    """Build a zip with one keyword-bearing member and one keyword-less 
("wrapped") member.
+
+    ``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).

Review Comment:
   Dropped it in a45c514830. 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



##########
airflow-core/src/airflow/dag_processing/manager.py:
##########
@@ -944,7 +965,10 @@ def find_zipped_dags(abs_path: os.PathLike) -> 
Iterator[str]:
             try:
                 with zipfile.ZipFile(abs_path) as z:
                     for info in z.infolist():
-                        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).

Review Comment:
   Done, went with your wording in a45c514830.
   
   ---
   Drafted-by: Claude Code (Fable 5); reviewed by @Vamsi-klu before posting



-- 
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]

Reply via email to