Skip to content

Add a way to differentiate between a task/DAG-level callback by context #61119

Closed

Description

@IndiTheo

Description

Currently, the context passed to a callback defined on DAG level looks pretty much the same as a context passed to a task callback. Thus, we the callback's code doesn't have a way to differentiate between the two cases (from experimentation I noted that the task-level callback has an exception field while the DAG callback doesn't, but it doesn't look reliable enough).

I expected the DAG-level callback to not have a task_instance field, but apparently it points to the last task executed.

I propose injecting a new field into the context that points to the parent object (TI or DAG) that caused the callback to be called / enum that signifies whether it's a task or a dag level callback.

Current workaround is writing a callback class that has a boolean flag and use partial when initializing it for DAG/task.

Use case/motivation

In my callback code I want to know which kind of callback was triggered and handle a failure accordingly.

Related issues

#26760

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:feature
    needs-triage
    on Jan 27, 2026
  2. IndiTheo commented on Jan 27, 2026

    @IndiTheo
    ContributorAuthor

    I'd like to work on this

  3. jroachgolf84 commented on Jan 27, 2026

    @jroachgolf84
    Collaborator

    @Asquator, please feel free to open up a PR for this issue.

  4. removed
    needs-triage
    on Jan 27, 2026
  5. tirkarthi commented on Jan 27, 2026

    @tirkarthi
    Contributor

    Related #26760

  6. IndiTheo commented on Jan 27, 2026

    @IndiTheo
    ContributorAuthor

    Found out that the context you see in DAG callbacks consists of task details of the last task in the DAG by lexicographical order - #26760 (comment)

    I think it's worth starting from changing this behavior and then adding some differentiation criteria (documenting it too)

  7. added a commit that references this issue on Jun 9, 2026
    35ae6dd
  8. added a commit that references this issue on Nov 1, 2026
    1c3252e
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:feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions