Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions airflow-core/newsfragments/49839.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The ``parsing_pre_import_modules`` setting is removed from code base.
It has no use in Airflow 3.
If your deployment override this setting you can safely remove it.
10 changes: 0 additions & 10 deletions airflow-core/src/airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2199,16 +2199,6 @@ scheduler:
type: integer
default: "20"
see_also: ":ref:`scheduler:ha:tunables`"
parsing_pre_import_modules:
description: |
The scheduler reads dag files to extract the airflow modules that are going to be used,
and imports them ahead of time to avoid having to re-do it for each parsing process.
This flag can be set to ``False`` to disable this behavior in case an airflow module needs
to be freshly imported each time (at the cost of increased DAG parsing time).
version_added: 2.6.0
type: boolean
example: ~
default: "True"
dag_stale_not_seen_duration:
description: |
Time in seconds after which dags, which were not updated by Dag Processor are deactivated.
Expand Down
21 changes: 0 additions & 21 deletions airflow-core/src/airflow/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# under the License.
from __future__ import annotations

import ast
import hashlib
import logging
import os
Expand Down Expand Up @@ -323,26 +322,6 @@ def might_contain_dag_via_default_heuristic(file_path: str, zip_file: zipfile.Zi
return any(s in content for s in (b"dag", b"asset"))


def _find_imported_modules(module: ast.Module) -> Generator[str, None, None]:
for st in module.body:
if isinstance(st, ast.Import):
for n in st.names:
yield n.name
elif isinstance(st, ast.ImportFrom) and st.module is not None:
yield st.module


def iter_airflow_imports(file_path: str) -> Generator[str, None, None]:
"""Find Airflow modules imported in the given file."""
try:
parsed = ast.parse(Path(file_path).read_bytes())
except Exception:
return
for m in _find_imported_modules(parsed):
if m.startswith("airflow."):
yield m


def get_unique_dag_module_name(file_path: str) -> str:
"""Return a unique module name in the format unusual_prefix_{sha1 of module's file path}_{original module name}."""
if isinstance(file_path, str):
Expand Down
47 changes: 0 additions & 47 deletions airflow-core/tests/unit/dags/test_imports.py

This file was deleted.

19 changes: 0 additions & 19 deletions airflow-core/tests/unit/utils/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,24 +193,6 @@ def test_might_contain_dag(self):
# With safe_mode is False, the user defined callable won't be invoked
assert file_utils.might_contain_dag(file_path=file_path_with_dag, safe_mode=False)

def test_get_modules(self):
file_path = os.path.join(TEST_DAGS_FOLDER, "test_imports.py")

modules = list(file_utils.iter_airflow_imports(file_path))

assert len(modules) == 4
assert "airflow.utils" in modules
assert "airflow.decorators" in modules
assert "airflow.models" in modules
assert "airflow.sensors" in modules
# this one is a local import, we don't want it.
assert "airflow.local_import" not in modules
# this one is in a comment, we don't want it
assert "airflow.in_comment" not in modules
# we don't want imports under conditions
assert "airflow.if_branch" not in modules
assert "airflow.else_branch" not in modules

def test_get_modules_from_invalid_file(self):
file_path = os.path.join(TEST_DAGS_FOLDER, "README.md") # just getting a non-python file

Expand All @@ -233,7 +215,6 @@ def test_list_py_file_paths(self, test_zip_path):
"test_invalid_param3.py",
"test_invalid_param4.py",
"test_nested_dag.py",
"test_imports.py",
"file_no_airflow_dag.py", # no_dag test case in test_zip folder
"test.py", # no_dag test case in test_zip_module folder
"__init__.py",
Expand Down
Loading