Repository navigation
Conversation
…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.
eba444b to
e6a5e87
Compare
|
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 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 |
Summary
A manually triggered Dag run's
logical_datecan coincide with a later, unrelated scheduled run'slogical_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). Thedag_runtable'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-missedWARNINGlog 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
dag_rununique constraint from(dag_id, logical_date)to(dag_id, logical_date, run_type).w only matchesSCHEDULEDruns, so a manual (or backfill/asset-triggered) run sharing alogical_dateis no longer mistaken for the scheduled run itself.SchedulerJobRunner._create_dag_runs's dedup lookup now only matchesSCHEDULEDruns, so a manual (or backfill/asset-triggered) run sharing alogical_dateis no longer mistaken for the scheduled run itself.Backfill._create_backfill_dag_run_non_partitionedand_handle_clear_runnow lock and update the specificDagRunrow byidinstead of by(dag_id, logical_date), since that pair can now match more than one row.test_scheduler_create_dag_runs_manual_run_does_not_block_scheduled_run(test_scheduler_job.py) andtest_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 indag_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 existing0032_..._rename_execution_date_to_logical_date_and_nullablemigration, which handles the equivalent case for NULLlogical_daterows the same way.closes: #41208
Was generative AI tooling used to co-author this PR?