wayblink commented on PR #77361: URL: https://github.com/apache/airflow/pull/77361#issuecomment-7032552275
Withdrawing this PR: the mechanism it relies on cannot occur in a valid 3.3.x metadata database, so there is nothing here to fix, and the change only weakens an intentional guard. **Why the premise does not hold** 1. The 3.3.1 migrations define `task_instance_history` as `PRIMARY KEY (task_instance_id)` plus `UNIQUE (dag_id, task_id, run_id, map_index, try_number)`. Several history rows cannot share one `task_instance_id`, so the primary-key collision described here cannot be produced by the archived attempts of a retried task. 2. Since 3.0.0, `TaskInstance.prepare_db_for_next_try()` archives the attempt and immediately reallocates the live row's identity (`self.id = uuid7()`), so an archived attempt's `task_instance_id` is not the live row's id either. Driving the 3.3.1 ORM through two retries ends with three distinct ids and an empty intersection between `task_instance_history.task_instance_id` and `task_instance.id`. 3. Constructing the scenario in the test added here fails on the schema itself: the second history row with the same `task_instance_id` raises `UNIQUE constraint failed: task_instance_history.task_instance_id`. That test only passed because its `_make_tables()` helper invents a schema whose primary key includes `try_number`, which is not the real predecessor schema. The only way to hit `duplicate key value violates unique constraint "task_instance_pkey"` in the restore is therefore a history row whose `id` already exists in `task_instance` — i.e. inconsistent data, which is exactly what `test_upgrade_does_not_suppress_unrelated_history_identity_conflict` is there to surface rather than silently discard. This also explains the failures in the last CI run: the guard test stops raising, and the new database-level test hangs because it creates and drops tables on a second connection while the `session` fixture still holds its transaction (60s timeout on PostgreSQL, `database is locked` on SQLite). If this failure is observed on a real database, the query that shows the shape is: ```sql SELECT h.task_instance_id FROM task_instance_history h JOIN task_instance t ON t.id = h.task_instance_id; ``` A non-empty result means the source data is inconsistent; a targeted fix can be designed from that, instead of ignoring every unique violation. --- Drafted-by: DeepSeek Harness agent (DeepSeek v4.1) (no human review before posting) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
