kir-rin opened a new pull request, #67325:
URL: https://github.com/apache/airflow/pull/67325
closes: #66104
## Problem
When `DAG_DISCOVERY_SAFE_MODE` is set to `False` in the config, Python files
without "airflow" or "dag" keywords are still being skipped during DAG
discovery.
This happens because the default argument `safe_mode=conf.getboolean(...)`
in
`list_py_file_paths()` is evaluated at module load time, not at call time.
Once evaluated, the value is fixed and subsequent config changes are ignored.
## Solution
Use the existing `NOTSET` sentinel pattern (already used in `DagBag`) to
defer
config reading to runtime:
```python
def list_py_file_paths(
directory: str | os.PathLike[str] | None,
safe_mode: bool | ArgNotSet = NOTSET,
) -> list[str]:
if not is_arg_set(safe_mode):
safe_mode = conf.getboolean("core", "DAG_DISCOVERY_SAFE_MODE",
fallback=True)
...
```
This ensures the config value is read at call time, allowing runtime config
changes to take effect.
## Testing
Added a test that would fail without this fix, verifying that:
- Files without keywords are skipped with `safe_mode=True`
- Files without keywords are found with `safe_mode=False`
- Config setting is now respected when using default argument
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — GLM-5
Generated-by: GLM-5 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]