Skip to content

Fixes #39793: stale foreign keys no longer block schema restore (backport 2.0 #39812) - #39843

Merged
manerow merged 1 commit into
2.0from
fix/39793-stale-fk-restore-2.0
Dec 4, 2026
Merged

manerow merged 1 commit into
2.0from
fix/39793-stale-fk-restore-2.0

Conversation

@manerow

@manerow manerow commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Issue

Partial cherry-pick of #39812 (Fixes #39793) onto 2.0.

Restoring a soft-deleted schema failed with Invalid column name <col> when a table in it had a foreign key to a column that was later removed from another table. 2.0.10 has the bug.

What this PR changes

  • A foreign key a table already stores is no longer rejected when its target column is gone. It is kept and a warning is logged, so keys left stale by older versions stop blocking writes and restores. A new or changed foreign key must still point to an existing column.
  • The error now names the table: Invalid column name pos_id in table <fqn>.

This is what makes the restore from the report succeed.

Not in this PR, and why

#39812 also drops the foreign keys in other tables when a column is removed. That part is left out on purpose. It must run only on the first diff pass of an update: session consolidation replays the same diff against older versions of the table, and there a column can wrongly look removed. 2.0 has no way to tell the first pass from a replay (main has it), and adding it is too large for a patch branch. Without that guard the cleanup could drop a foreign key that still points to an existing column.

On 2.0, removing a column still leaves the stale key on the other table. It no longer blocks a restore or any other write.

Differences from main

  • The cleanup code and its 3 tests are not included.
  • The error test uses assertThrows, because 2.0 has no ApiAssertions.
  • The conflicts in TableRepository were around code that main changed after 2.0 branched.

Tests

Backend integration tests, in TableResourceIT:

  • A table that already stores a stale foreign key restores, and the key is kept.
  • A new foreign key to a missing column returns 400, and the message names the table.

Both new tests and the 3 existing column-removal tests pass on MySQL (5 of 5) on this branch. Both new tests fail on the original 2.0 code; the restore fails with the reported Invalid column name pos_id.

Not run: Postgres and the rest of TableResourceIT on 2.0.

@manerow
manerow requested a review from a team as a code owner December 4, 2026 13:29
@manerow
manerow requested review from IceS2 and removed request for a team December 4, 2026 13:29
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@gitar-bot

gitar-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk

Allowing unchanged foreign keys to reference removed columns may preserve stale relationship metadata during restores, while new or edited keys remain validated.

Backports the fix so a soft-deleted schema can be restored when a table stores a foreign key to a column that was later removed. Stale foreign keys are kept with a logged warning, and new foreign keys to missing columns now return a 400 error that names the table. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@manerow
manerow merged commit 6a07972 into 2.0 Dec 4, 2026
61 of 63 checks passed
@manerow
manerow deleted the fix/39793-stale-fk-restore-2.0 branch December 4, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant