Skip to content

Allow user DAGs to emit DagWarning (or similar) #29275

Description

@Gollum999

Description

I would like a way to emit a warning or error message from a DAG that shows up as a banner in the web UI, similar to how exceptions are handled during DAG parsing or how DagWarnings are displayed.

Use case/motivation

I have a script under my dags_folder that is dynamically discovering and building DAGs from a networked filesystem. If one dynamically discovered DAG raises an exception, I don't want that to affect any of the other DAGs that are being discovered, so I swallow exceptions and log about them. However, I have not found a good way to communicate to my users that that exception occurred. Ideally I think it should look similar to when an exception is raised in a traditional DAG - an error banner on the web with (optionally) the full traceback.

In my testing, I've found that if any exception is raised during DAG parsing, it causes all DAGs originating from that file to be removed. So this sort of thing does not work:

#!/usr/bin/env python3
from datetime import datetime
import traceback

from airflow.decorators import dag, task


exceptions = []
for dag_id in 'ABCDE':
    try:
        @dag(
            dag_id=dag_id,
            schedule=None,
            start_date=datetime(2023, 1, 31),
        )
        def test_multi_exception():
            if dag_id in 'BE':
                raise RuntimeError(f'Failed to create dynamic DAG {dag_id}')

            @task
            def t():
                print('inside task')

            t()

        test_multi_exception()

    except Exception as e:
        exceptions.append(''.join(traceback.format_exception(etype=type(e), value=e, tb=e.__traceback__)))

if exceptions:
    raise RuntimeError('\n'.join(exceptions))

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. potiuk commented on Feb 19, 2023

    @potiuk
    Member

    Yes it would be interesting feature to add.

  2. Gowthami03B commented on Apr 3, 2023

    @Gowthami03B

    Can I take this one ?

  3. Robertas-V commented on Apr 10, 2024

    @Robertas-V

    Ah, I was looking for such great feature in Airflow but it seems to be stuck, isn't it?

  4. removed their assignment
    on Apr 21, 2024
  5. gabryuri commented on Jul 6, 2024

    @gabryuri

    I'd love to work on this one

  6. potiuk commented on Mar 2, 2026

    @potiuk
    Member

    @gabryuri We are unassigning you from this issue as part of our updated assignment policy.

    This is not meant to discourage your contribution — quite the opposite! You are still very welcome to work on this issue and submit a PR for it. Simply comment that you are working on it and open a PR when ready.

    We found that formal assignments were not working well, as they often prevented others from contributing when the assignee was not actively working on the issue.

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