Repository navigation
Description
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:
- Fresh 3.3.1 install, Postgres, any Dag.
- Trigger a run and leave it un-started.
- Mark the run as success (or failed) from the UI, leaving the Note box empty.
- The red "Conflict" toast appears; the run is nevertheless marked and its
task instances updated. - 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
- I agree to follow this project's Code of Conduct
Activity
boring-cyborg commentedon Sep 15, 2026
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.
DianaHov commentedon Sep 15, 2026
I can put up a PR if none of the maintainers have time for it, just let me know.
namanjain24-sudo commentedon Sep 15, 2026
Hi @DianaHov, I'd like to work on this issue and submit a PR to fix the regression in Airflow 3.3.1.
DianaHov commentedon Sep 15, 2026
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.
namanjain24-sudo commentedon Sep 15, 2026
Thanks @DianaHov. Before starting a PR I checked
main, and this exact change has already landed: #71488 passessession=sessiontoti.set_statein_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.2rc1tag 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 thedag_run_noteinsert whenevernoteis 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.
DianaHov commentedon Sep 15, 2026
@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!
shahar1 commentedon Sep 15, 2026
Closing as it has already been fixed.
Please let us know if you encounter any related issues after upgrading.