Skip to content

Fix manually triggered runs blocking a scheduled run at the same logical_date - #72003

Closed
ColtenOuO wants to merge 2 commits into
apache:mainfrom
ColtenOuO:fix-manual-run-blocks-scheduled-same-logical-date
Closed

ColtenOuO wants to merge 2 commits into
apache:mainfrom
ColtenOuO:fix-manual-run-blocks-scheduled-same-logical-date

Conversation

@ColtenOuO

Copy link
Copy Markdown
Contributor

Summary

A manually triggered Dag run's logical_date can coincide with a later, unrelated scheduled run's logical_date -- they represent different data intervals despite sharing that value (a manual trigger's data interval is derived from when it fires, not the period it's labeled with). The dag_run table's (dag_id, logical_date) uniqueness constraint didn't distinguish between run types, so whichever run landed first silently and permanently claimed that logical_date: the scheduler's dedup check would find the manual run, assume the scheduled run for that period already existed, and skip creating it -- dropping that scheduling period for good, with only an easily-missed WARNING log as a trace.

This isn't only an in-memory dedup-check bug. Verified directly against the metadata database: even bypassing the scheduler's pre-check, inserting the correctly-computed scheduled run fails with the same unique-constraint violation as long as a manual run already occupies that (dag_id, logical_date) pair. The fix has to widen what the database considers a duplicate, not just how the scheduler checks for one.

Change

  • Added a migration widening the dag_run unique constraint from (dag_id, logical_date) to (dag_id, logical_date, run_type).w only matches SCHEDULED runs, so a manual (or backfill/asset-triggered) run sharing a logical_date is no longer mistaken for the scheduled run itself.
  • SchedulerJobRunner._create_dag_runs's dedup lookup now only matches SCHEDULED runs, so a manual (or backfill/asset-triggered) run sharing a logical_date is no longer mistaken for the scheduled run itself.
  • Backfill._create_backfill_dag_run_non_partitioned and _handle_clear_run now lock and update the specific DagRun row by id instead of by (dag_id, logical_date), since that pair can now match more than one row.
  • Added test_scheduler_create_dag_runs_manual_run_does_not_block_scheduled_run (test_scheduler_job.py) and test_handle_clear_run_only_updates_the_targeted_run (test_backfill.py) as regression tests; both confirmed to fail without their corresponding fix.

Downgrade handling

After this constraint has been in effect, data can legitimately exist that violates the narrower, pre-migration constraint (a manual and a scheduled run sharing a logical_date), so downgrading straight to the old constraint would fail outright. The downgrade first finds every (dag_id, logical_date) group with more than one row, keeps the lowest-id row of each group in dag_run, and moves the rest into an _airflow_moved__-prefixed table before re-adding the narrower constraint -- data is preserved for review, not discarded. This mirrors the existing 0032_..._rename_execution_date_to_logical_date_and_nullable migration, which handles the equivalent case for NULL logical_date rows the same way.

closes: #41208


Was generative AI tooling used to co-author this PR?
  • Yes -- Claude Code (Sonnet 5) for writing test

@ColtenOuO ColtenOuO changed the title Fix manually triggered runs blocking a scheduled run at the same logi… Fix manually triggered runs blocking a scheduled run at the same logical_date Aug 23, 2026
…cal_date

A manually triggered Dag run's logical_date can coincide with a later,
unrelated scheduled run's logical_date -- they represent different data
intervals despite sharing that value, since a manual trigger's data
interval is derived from when it fires rather than from the period it
is labeled with. The DagRun table's uniqueness constraint didn't
distinguish between run types, so whichever run landed first silently
and permanently claimed that logical_date, and the scheduler treated
the other as a duplicate it had "already handled" -- dropping that
scheduling period for good, with only an easily-missed WARNING log as
a trace.

Verified directly against the metadata database that this isn't just
an in-memory dedup-check problem: a manual run occupying a logical_date
makes the scheduled run's INSERT fail on the same unique-constraint
violation regardless of how the scheduler checks for duplicates
beforehand, so the fix widens what the database itself considers a
duplicate rather than just how the scheduler looks for one.
@ColtenOuO
ColtenOuO force-pushed the fix-manual-run-blocks-scheduled-same-logical-date branch from eba444b to e6a5e87 Compare August 25, 2026 20:23
@potiuk potiuk added the closed because of open PR limit Closed as a one-time step of introducing the open pull request limit label Sep 25, 2026
@potiuk

potiuk commented Sep 25, 2026

Copy link
Copy Markdown
Member

Hello @ColtenOuO - thank you for your contributions to Apache Airflow!

The Airflow community has introduced a limit of 5 open pull requests at a time for contributors without write access to the repository. You currently have 19 open pull requests, so - as a one-time step of introducing the limit - we closed the ones where maintainers have not engaged yet:

These pull requests stay open because maintainers are already engaged in them - they count towards your limit:

This is not a judgement of you or of your changes. We never told contributors before that opening many pull requests at once was a problem, so there is nothing to feel bad about - and nothing is lost: your branches, commits and the review history stay where they are.

What we ask you to do is to make your first prioritization decision: choose which of the pull requests above matter most to you, and reopen them (up to 5 open at a time, including the ones still open) with the "Reopen pull request" button or gh pr reopen <PR_NUMBER> --repo apache/airflow. Reopen the ones you are ready to follow through - keep them rebased, respond to review comments and fix failing checks.

While your pull requests are waiting for review, the most valuable thing you can do is help in other ways - reviewing other contributors' pull requests, helping with issues, and taking part in the discussions on the devlist and Slack.

Why we introduced the limit, what it means for you and how to reopen or restore a pull request is explained in https://github.com/apache/airflow/blob/main/contributing-docs/32_open_pull_request_limit.rst.


Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:db-migrations PRs with DB migration area:scheduler closed because of open PR limit Closed as a one-time step of introducing the open pull request limit kind:documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Manual run with same execution date as scheduled run causes the scheduled run to be skipped.

2 participants