Skip to content

Populate dag and note before firing dag run state-change listeners - #69873

Merged
pierrejeambrun merged 2 commits into
apache:mainfrom
kacpermuda:dag-listeners-extend
Jul 22, 2026
Merged

Populate dag and note before firing dag run state-change listeners#69873
pierrejeambrun merged 2 commits into
apache:mainfrom
kacpermuda:dag-listeners-extend

Conversation

@kacpermuda

@kacpermuda kacpermuda commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

When patching a Dag Run's state to success or failed via the API, two issues
existed with the listener call:

  1. dag_run.dag was always None when the listener received the object, because the route loads the dag separately but never attached it to the run. After the change, the listener will have access to SerializedDag that is used for example by OpenLineage listener to create an AirflowDagRunFacet.
  2. The listener message was an empty string. After the change, we will match the messages passed to task listener methods when manually changing task's state. It will make it easier for listener (and end users) to figure out what caused the early success / failure of dagrun.
  3. When both note and state were patched in the same request (dagrun state was set and note was provided), the note could be applied after the listener fired, so the listener saw the old / no note. Fixed by sorting the patch fields so note is always processed before state.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Sonnet 4.6
    Generated-by: Claude Sonnet 4.6 following the guidelines

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

Comment thread airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py Outdated

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks overall looking good beside Amogh's comment.

Comment thread airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py Outdated
@kacpermuda
kacpermuda force-pushed the dag-listeners-extend branch from 5704cd3 to 1cdf0dc Compare July 15, 2026 11:56

@amoghrajesh amoghrajesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks LGTM!

@pierrejeambrun pierrejeambrun added this to the Airflow 3.3.1 milestone Jul 22, 2026
@pierrejeambrun pierrejeambrun added the backport-to-v3-3-test Backport to v3-3-test label Jul 22, 2026
Comment thread airflow-core/tests/unit/listeners/class_listener.py
@pierrejeambrun
pierrejeambrun merged commit ec8da5c into apache:main Jul 22, 2026
84 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

Backport successfully created: v3-3-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-3-test PR Link

@kacpermuda
kacpermuda deleted the dag-listeners-extend branch July 22, 2026 16:45
pierrejeambrun pushed a commit that referenced this pull request Jul 22, 2026
…listeners (#69873) (#70245)

* Populate dag and note before firing dag run state-change listeners

* Address PR review
(cherry picked from commit ec8da5c)

Co-authored-by: Kacper Muda <mudakacper@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request Aug 5, 2026
…listeners (#69873) (#70245)

* Populate dag and note before firing dag run state-change listeners

* Address PR review
(cherry picked from commit ec8da5c)

Co-authored-by: Kacper Muda <mudakacper@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API backport-to-v3-3-test Backport to v3-3-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants