Skip to content

Fix: Restore task_instance_history sequence on downgrade#61976

Merged
vatsrahul1001 merged 7 commits into
apache:mainfrom
astronomer:fix-tih-seq
Mar 3, 2026
Merged

Fix: Restore task_instance_history sequence on downgrade#61976
vatsrahul1001 merged 7 commits into
apache:mainfrom
astronomer:fix-tih-seq

Conversation

@vatsrahul1001

@vatsrahul1001 vatsrahul1001 commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

During a rollback from Airflow 3 to Airflow 2, the task_instance_history_id_seq PostgreSQL sequence was not being recreated. This caused task_instance_history inserts to fail with NULL constraint violations since the id column had no DEFAULT value for auto-increment.

Root Cause

In the upgrade path (migration 0060), the id column is dropped:
batch_op.drop_column("id")When PostgreSQL drops a column with an associated sequence, the sequence is also dropped (due to ownership).

Testing

  1. Run command breeze start-airflow --executor CeleryExecutor --backend postgres
  2. Down try downgarding airflow db downgrade --to-revision e00344393f31 -y
  3. Verify Seq is getting created after downgrade
image
  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@vatsrahul1001 vatsrahul1001 added this to the Airflow 3.1.8 milestone Mar 2, 2026
@vatsrahul1001

Copy link
Copy Markdown
Contributor Author

@ephraimbuddy could use a re-review

@ephraimbuddy ephraimbuddy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sqlite branch might not also give a deterministic sequence but since it's sqlite, we can ignore it.

LGTM, just nit

@vatsrahul1001 vatsrahul1001 merged commit 5d9b5df into apache:main Mar 3, 2026
129 checks passed
@vatsrahul1001 vatsrahul1001 deleted the fix-tih-seq branch March 3, 2026 05:19
@github-actions

github-actions Bot commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Backport failed to create: v3-1-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-1-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 5d9b5df v3-1-test

This should apply the commit to the v3-1-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

vatsrahul1001 added a commit that referenced this pull request Mar 3, 2026
* fix: restore task_instance_history_id_seq during downgrade

(cherry picked from commit 5d9b5df)
vatsrahul1001 added a commit that referenced this pull request Mar 3, 2026
* fix: restore task_instance_history_id_seq during downgrade

(cherry picked from commit 5d9b5df)
@vatsrahul1001 vatsrahul1001 added the type:bug-fix Changelog: Bug Fixes label Mar 3, 2026
@vatsrahul1001 vatsrahul1001 removed this from the Airflow 3.1.8 milestone Mar 3, 2026
dominikhei pushed a commit to dominikhei/airflow that referenced this pull request Mar 11, 2026
* fix: restore task_instance_history_id_seq during downgrade
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 type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants