Skip to content

`dag_discovery_safe_mode not scanning all files when set to False #66104

Closed

Description

@dayonet

Under which category would you file this issue?

Airflow Core

Apache Airflow version

3.0.3

What happened and how to reproduce it?

Issue Description

Airflow does not parse all files even though dag_discovery_safe_mode = false.
We created an internal wrapper for Airflow, so we import definitions from our wrapper and not directly from Airflow. This results in whole projects that define Airflow DAGs and Tasks that don't have the words "airflow" or "dag" in them at all.
In order for Airflow to still parse the wrapped DAGs, we need it to parse all files, disregarding the existence of "airflow" and "dag" being present.
In order to achieve this we set dag_discovery_safe_mode = false, but the DAGs still don't appear.
They appear after running airflow dags reserialize, but disappear after a few minutes each time.
They obviously appear permanently if we add "airflow" and "dag" to the files, but we're trying to avoid this solution.

Steps to reproduce

-> Create an Airflow DAG wrapper with names not containing "airflow" or "dag"
-> Turn dag_discovery_safe_mode to False
-> Wrapped DAGs don't appear in UI
-> After running airflow dags reserialize they appear, but disappear shortly after
-> Adding "# DAG airflow" or "from airflow.sdk import dag" makes them appear permanently

simple DAG wrapping

from functools import wraps
from airflow import DAG
from airflow.sdk import dag


@wraps(dag)
def flow(*dag_args, **dag_kwargs):
    def decorator(func):
        @wraps(func)
        def wrapper(*args, **kwargs):
            with DAG(dag_id=func.__name__, *dag_args, **dag_kwargs) as dag:
                func(*args, **kwargs)
        return wrapper
    return decorator

What you think should happen instead?

After setting dag_discovery_safe_mode = false wrapped DAGs will permanently appear in UI and be parsed normally.

Operating System

Run on OpenShift

Deployment

Official Apache Airflow Helm Chart

Apache Airflow Provider(s)

No response

Versions of Apache Airflow Providers

No response

Official Helm Chart version

1.18.0

Kubernetes Version

OpenShift 4.16

Helm Chart configuration

No response

Docker Image customizations

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Apr 29, 2026
  2. boring-cyborg commented on Apr 29, 2026

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

  3. saidiraja commented on Apr 29, 2026

    @saidiraja
    Contributor

    Reproduction attempt (Airflow 3.2.0)

    Environment

    • Airflow: 3.2.0
    • Python: 3.12.3
    • OS: Ubuntu (WSL2)
    • Deployment: local virtualenv

    What I tested

    I created a DAG file (hidden_flow.py) that does not explicitly contain typical keywords like "airflow" or "dag".

    Then I disabled safe mode:

    export AIRFLOW__CORE__DAG_DISCOVERY_SAFE_MODE=False

    and verified:

    airflow config get-value core dag_discovery_safe_mode

    False

    Observations

    • The DAG was detected when loading via DagBag:
      HAS SAFE_MODE_TEST_66104: True

    • However, it was not listed initially using:
      airflow dags list

    • After starting Airflow using:
      airflow standalone

      the DAG appeared in the list, could be triggered, and runs were created successfully.

    Result

    I was not able to fully reproduce the exact issue described.

    DAG parsing works correctly when safe mode is disabled, but DAG visibility seems to depend on the scheduler/services being running.

    Evidence

    Screenshots attached showing:

    • DAG not listed initially
    • DagBag detecting the DAG
    • DAG appearing after starting Airflow
    • Successful DAG run
    Image Image Image Image Image
  4. dayonet commented on Apr 30, 2026

    @dayonet
    Author

    Thank you for the quick reply. I ran the commands and I found that they really do appear when running airflow dags list and can be triggered via airflow dags trigger <dag_id>, which is great!
    Still, they don't appear in the Airflow UI without running airflow dags reserialize every few minutes.
    We give our Airflow to users in our company so it's important they can see them in the UI and trigger from there as well.
    Is there a way to make them appear in the UI permanently?

  5. saidiraja commented on Apr 30, 2026

    @saidiraja
    Contributor

    Thanks for sharing this , I was able to reproduce the same behavior on my side.

    With dag_discovery_safe_mode=False, the DAG is:

    • visible via airflow dags list
    • triggerable via CLI

    However, I also observed that it does not appear in the UI unless airflow dags reserialize is run manually.

    From what I understand, this may be because DAG discovery (used by CLI) and DAG serialization (used by the UI) are handled separately. The UI relies on the scheduler to serialize DAGs into the metadata DB, so if that step is not triggered automatically, the DAG won’t appear there.

    So it seems the issue might not only be about file scanning, but also how DAGs are picked up for serialization when safe mode is disabled.

    Curious to hear if others have seen similar behavior or have more insights on this.

  6. dayonet commented on May 1, 2026

    @dayonet
    Author

    Thank you for the quick and helpful reply.

    Since this problem is currently a showstopper for me, I'd like to know if fixing it is on your roadmap (at least in terms of a workaround).
    I'm not sure I'm in a position to submit a PR, but I'd like to understand my options.

    Happy to help test or provide more details if that’s useful.

  7. dayonet commented on May 20, 2026

    @dayonet
    Author

    Hi,
    Is this supposed to be solved in future versions?

  8. dayonet commented on May 24, 2026

    @dayonet
    Author

    From what I understand from the PR, the conclusion is that the bug's behavior is as expected due to Airflow's evaluation of default arguments at module load time.
    Although I understand that this is the default behavior, I'd appreciate it if a workaround or more robust solution could be provided, since it is causing a concrete bug that's a big issue in our organization.

  9. kir-rin commented on May 25, 2026

    @kir-rin
    Contributor

    I'm the author of #67325. I'm leaving this comment to explain why I closed the PR.

    Since config changes require a restart, I don't think the default argument evaluation at module load time is a bug.

    I tried to reproduce the issue to identify the actual root cause, but couldn't — the DAG files appeared in the UI correctly in my tests.

    I tested both airflow standalone and separate scheduler + api-server + processor setups.

    Example files I used (same wrapper pattern from the issue description):

    • dags/wrapper/flow.py — the wrapper decorator
    • dags/test.py — uses the wrapper, also no keywords
    from datetime import datetime
    from wrapper.flow import flow
    
    @flow(schedule=none, start_date=datetime(2024, 1, 1))
    def test():
        print("hello")
    
    test()

    The DAG was discovered and visible in the UI after setting DAG_DISCOVERY_SAFE_MODE=False and restarting.

  10. dayonet commented on May 31, 2026

    @dayonet
    Author

    Did the DAG stay in the UI after the next DAG serialization? In my experience it shows up in the UI for a few minutes, and then disappears. It returns upon running airflow dags reserialize, and disappears again on the next automatic reserialization, just like @saidiraja experienced.

  11. added a commit that references this issue on Aug 10, 2026
    2e8c024
  12. added a commit that references this issue on Aug 17, 2026
    786dd79
  13. added 2 commits that reference this issue on Aug 17, 2026
    c90a129
    3426221
  14. added a commit that references this issue on Sep 7, 2026
    7f0f949
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corekind:bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions