Skip to content

Marking a Dag run success/failed returns 409 Conflict on first attempt (3.3.1 regression) #73152

Closed as not planned

Description

@DianaHov

Under which category would you file this issue?

Airflow Core

Apache Airflow version

3.3.1

What happened and how to reproduce it?

Marking a Dag run as success or failed from the UI returns 409 Conflict
("Update Dag Run Request Failed"), but the change is applied anyway - the run
and its task instances are updated, and the UI shows an error for an operation
that actually succeeded.

It only happens the first time a given run is marked. Marking the same run
again succeeds with no error.

The api-server log shows:

Error with id ..., statement: INSERT INTO dag_run_note (user_id, dag_run_id, content, created_at, updated_at) VALUES (...)

i.e. a duplicate-key violation on dag_run_note, surfaced as 409 by
_UniqueConstraintErrorHandler. It happens even with the Note field left empty.

Works correctly in 3.3.0.

To reproduce:

  1. Fresh 3.3.1 install, Postgres, any Dag.
  2. Trigger a run and leave it un-started.
  3. Mark the run as success (or failed) from the UI, leaving the Note box empty.
  4. The red "Conflict" toast appears; the run is nevertheless marked and its
    task instances updated.
  5. Mark the same run again - this time it succeeds silently.

What you think should happen instead?

The request should return 200 and no duplicate insert should be attempted.


The cause is in _set_dag_run_terminal_state
(airflow-core/src/airflow/api/common/mark_tasks.py):

for ti in pending_normal_tis:
    ti.set_state(TaskInstanceState.SKIPPED)

TaskInstance.set_state is decorated with @provide_session and no session is
passed here, so it opens its own session, calls session.merge(self) and
commits it. TaskInstance.dag_run is lazy="joined", so that merge cascades
TI → DagRun → dag_run_note and carries the still-unflushed DagRunNote into
the second session, which commits it. The request's session then commits its
own copy of the same row, and the second insert violates dag_run_note_pkey.

This surfaces in 3.3.1 because patch_dag_run now applies the note before the
state, so a note is attached to the DagRun at the moment that merge happens. In
3.3.0 the state ran first and there was nothing to cascade.

The fix is to pass the session through:

for ti in pending_normal_tis:
    ti.set_state(TaskInstanceState.SKIPPED, session=session)

That keeps the note-before-state ordering intact and produces a single insert.
Verified locally on 3.3.1: the 409 is gone, and the run and its task instances
update as expected.

Operating System

macOS

Deployment

Other

Apache Airflow Provider(s)

No response

Versions of Apache Airflow Providers

No response

Official Helm Chart version

Not Applicable

Kubernetes Version

No response

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 Sep 15, 2026
  2. boring-cyborg commented on Sep 15, 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. DianaHov commented on Sep 15, 2026

    @DianaHov
    Author

    I can put up a PR if none of the maintainers have time for it, just let me know.

  4. namanjain24-sudo commented on Sep 15, 2026

    @namanjain24-sudo
    Contributor

    Hi @DianaHov, I'd like to work on this issue and submit a PR to fix the regression in Airflow 3.3.1.

  5. DianaHov commented on Sep 15, 2026

    @DianaHov
    Author

    Thanks @namanjain24-sudo, go ahead.

    One bit of context: we're staying on 3.3.0 because of this, and I have a
    separate feature request I'm planning to submit a PR for, which would need a
    later version - so getting this into a patch release sooner would help us.

    No pressure at all. If you can pick it up in the next week or two that's
    perfect. If it looks like taking longer, just say and I'll take it over.

  6. namanjain24-sudo commented on Sep 15, 2026

    @namanjain24-sudo
    Contributor

    Thanks @DianaHov. Before starting a PR I checked main, and this exact change has already landed: #71488 passes session=session to ti.set_state in _set_dag_run_terminal_state. It was merged as a performance fix, so it never got linked to this issue. It was backported in #71955 and is included in 3.3.2rc1, which is on PyPI.

    I verified it against the 3.3.2rc1 tag on Postgres 16 with an API test on an un-started run: marking it success or failed now returns 200 on the first attempt. With that one line reverted to its 3.3.1 form, the same test returns the 409 on the dag_run_note insert whenever note is null (what the UI sends when the run has no note and the Note box is left untouched) or has text.

    So there's nothing left to fix, and I won't be opening a separate PR. If you get a chance to try 3.3.2rc1 in your setup, a comment on #73089 (the RC testing issue) would help the release along, and this issue can then be closed as fixed by #71955.

  7. DianaHov commented on Sep 15, 2026

    @DianaHov
    Author

    @namanjain24-sudo thank you! good catch - I hadn't checked main. I can see the change in the 3.3.2rc1 wheel.

    I'll test the RC in our setup and comment on #73089, then close this as fixed by #71955.

    TY!

  8. shahar1 commented on Sep 15, 2026

    @shahar1
    Contributor

    Closing as it has already been fixed.
    Please let us know if you encounter any related issues after upgrading.

  9. added and removed
    needs-triage
    on Sep 15, 2026
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:bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions