Skip to content

Dags list/list-import-errors cli commands broken and don't track local DagBag #49330

Closed

Description

@dheerajturaga

Apache Airflow version

3.0.0

If "Other Airflow 2 version" selected, which one?

No response

What happened?

When developing dags, airflow dags list and airflow dags list-import-errors return No data found when the database has just been initialized. Also any update to the dags aren't reflected with these commands unless you run airflow dags reserialize. THe command only reads from db, it should also track localdag bag similar to airflow 2. This is a serious problem as these commands are used widely in dag development.

This is happening because these commands are reading from the db rather than tracking the local dagbag.
DagBag(read_dags_from_db=True)

What you think should happen instead?

Given we are always reading from the db in the case of list and list-import-errors we need to run reserialize before fetching these values from the database

How to reproduce

Seed a basic dag in the dags directory and run. Just use the defaults.

airflow db migrate
airflow dags list

Operating System

Ubuntu 24.04.1 LTS

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

Deployment details

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. bugraoz93 commented on Apr 16, 2025

    @bugraoz93
    Contributor

    I think this should already be from db. Because let's say you have airflow.cfg with proper jdbc connection and network rules, you can execute this command from a remote machine rather than in the component container or operating system then you won't have local DAGBag anymore. I don’t think this is a bug though
    Reviewed the PR :)

  2. removed
    kind:bugThis is a clearly a bug
    needs-triagelabel for new issues that we didn't triage yet
    on Apr 16, 2025
  3. dheerajturaga commented on Apr 16, 2025

    @dheerajturaga
    MemberAuthor

    @bugraoz93 Thats only if you have a dag-processor running. in airflow 2.10.5 this command reads directly from the repo rather than the db. The current implementation breaks local DagBag development and requires you to have a dag-processor job actively running during dag development. We should support both scenarios

    I have a setup where I just have the following settings in a source_me in my dags repository and I use airflow dags list-import-errors
    while editing my dags

    AIRFLOW_HOME = '<dags_repo>/run'
    AIRFLOW__CORE__DAGS_FOLDER = <dags_repo>
    AIRFLOW__CORE__LOAD_EXAMPLES = false
    

    in this setup airflow info will auto create a airflow.cfg and airflow.db in the dags_repo/run area. Its a downgrade if we need to airflow dags reserialize and then airflow dags list-import-errors every time instead of just airflow dags list-import-errors to figure out whats wrong ( which was the case in airflow 2 )

  4. bugraoz93 commented on Apr 16, 2025

    @bugraoz93
    Contributor

    @bugraoz93 Thats only if you have a dag-processor running. in airflow 2.10.5 this command reads directly from the repo rather than the db. The current implementation breaks local DagBag development and requires you to have a dag-processor job actively running during dag development. We should support both scenarios

    I have a setup where I just have the following settings in a source_me in my dags repository and I use airflow dags list-import-errors
    while editing my dags

    AIRFLOW_HOME = '<dags_repo>/run'
    AIRFLOW__CORE__DAGS_FOLDER = <dags_repo>
    AIRFLOW__CORE__LOAD_EXAMPLES = false
    

    in this setup airflow info will auto create a airflow.cfg and airflow.db in the dags_repo/run area. Its a downgrade if we need to airflow dags reserialize and then airflow dags list-import-errors every time instead of just airflow dags list-import-errors to figure out whats wrong ( which was the case in airflow 2 )

    I want to clarify some parts. I see that the issue opened as 3.0.0, which is the current main branch. In Airflow 3.0 (main branch), there will be Dag Processors running. All the CLI commands are updated according to the dag bundle and versioning, which is managed by Dag Processors. So, in the context of 3.0.0, I think this is not a problem but already planned changes.
    See https://github.com/apache/airflow/blob/main/airflow-core/newsfragments/45729.significant.rst

    Current latest development version of 2.10
    https://github.com/apache/airflow/tree/v2-10-test

    Stable
    https://github.com/apache/airflow/tree/v2-10-stable

  5. dheerajturaga commented on Apr 16, 2025

    @dheerajturaga
    MemberAuthor

    @bugraoz93 , I have been testing airflow 3.0.0rc2 for a couple of days when I noticed this. So you are saying the only way to reflect the true state of the dags in a "out of the box/local" setting is to spin up a dag-processor in that local setup and then run the cli commands?

    Don't you think we should add a --local arg ( or something similar ) to the list and list-import-errors to be able to iterate on during dag development in user's local areas?

  6. bugraoz93 commented on Apr 16, 2025

    @bugraoz93
    Contributor

    @bugraoz93 , I have been testing airflow 3.0.0rc2 for a couple of days when I noticed this. So you are saying the only way to reflect the true state of the dags in a "out of the box/local" setting is to spin up a dag-processor in that local setup and then run the cli commands?

    Don't you think we should add a --local arg ( or something similar ) to the list and list-import-errors to be able to iterate on during dag development in user's local areas?

    Yes, exactly for Airflow 3.0+. I don’t think that should be needed. How are you testing locally? If you are using Breeze, the start-airflow command should already run the standalone Dag Processors. Or if you are using docker-compose or helm charts in minikube or so. It should be already running out of the box.

    Breeze
    https://github.com/apache/airflow/blob/main/dev/breeze/doc/03_developer_tasks.rst
    Compose

    test: ["CMD-SHELL", 'airflow jobs check --job-type DagProcessorJob --hostname "$${HOSTNAME}"']

    Helm
    ## Airflow Dag Processor Deployment

  7. dheerajturaga commented on Apr 16, 2025

    @dheerajturaga
    MemberAuthor

    @bugraoz93 , We dont use docker at all (and have no access to it either). We use virtualenvs. As mentioned, the setup here is pretty light weight where airflow cli comes from a local venv where airflow is installed. We just have these three env variables that go with it.

    AIRFLOW_HOME = '<dags_repo>/run'
    AIRFLOW__CORE__DAGS_FOLDER = <dags_repo>
    AIRFLOW__CORE__LOAD_EXAMPLES = false
    

    Being able to list dags and list import errors without having any services running is a valid and wide spread usecase. This is how folks sanity check their dags and maybe even run airflow standalone for a quick dry run before they deploy to the central airflow service

  8. bugraoz93 commented on Apr 16, 2025

    @bugraoz93
    Contributor

    @bugraoz93 , We dont use docker at all (and have no access to it either). We use virtualenvs. As mentioned, the setup here is pretty light weight where airflow cli comes from a local venv where airflow is installed. We just have these three env variables that go with it.

    AIRFLOW_HOME = '<dags_repo>/run'
    AIRFLOW__CORE__DAGS_FOLDER = <dags_repo>
    AIRFLOW__CORE__LOAD_EXAMPLES = false
    

    Being able to list dags and list import errors without having any services running is a valid and wide spread usecase. This is how folks sanity check their dags and maybe even run airflow standalone for a quick dry run before they deploy to the central airflow service

    I am saying that Dag Processors should be running when deploying Airflow 3.0+ to any environment. I don’t know the details of your setup but when you say local, I understand as it is local machine you are using for development if that is running the airflow api-server, scheduler or triggerer in a venv, then yes Dag Processors should be running there too. Even in on-premise server or docker that shouldn't really make any difference in this scenario. If venv is remote and you are connecting, not in your personal local machines but somewhere in a server then it should be running there

  9. bugraoz93 commented on Apr 16, 2025

    @bugraoz93
    Contributor

    self.subcommands["dag-processor"] = SubCommand(

    airflow standalone also should run Dag Processors too

  10. bugraoz93 commented on Apr 16, 2025

    @bugraoz93
    Contributor

    By the way, theairflow service you mentioned should be in the same version too, when you use airflow 3.0 CLI. 3.0.0rc2 in this case

  11. dheerajturaga commented on Apr 16, 2025

    @dheerajturaga
    MemberAuthor

    If you look at it from a newbie dag author perspective, you dont have any services running nor do you intend to deploy Airflow3 service either.

    You just have access to a dags dir and a airflow install (cli) through venv.

    Airflow 2 can simply list my import errors without needing to have any service up and running.
    Airflow 3 requires me to have a dag processor running which is unnecessary when someone is developing their dags and just want to check for syntax issues. ( This setup is not for official deployment but for local dag development)

    I am aware that standalone does launch all services but having to run a whole service to simply check syntax issues and list dags I have in my dagbag seems overkill.

    I have a PR in the pipeline which adds back the original functionality with the --local option. Please review it once I push

  12. dheerajturaga commented on Apr 17, 2025

    @dheerajturaga
    MemberAuthor

    @bugraoz93 I moved the original functionality under --local argument. I added some tests as well. Let me know what you think!
    If you think this should rather be a separate CLI command, I can do that aswell

    Thanks for reviewing this request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions