Skip to content

Fixes #34933: Match FK referred columns to the parent table's column case [Backport #34934 - 2.0] - #35311

Merged
harshsoni2024 merged 1 commit into
2.0from
backport-34934-2.0
Oct 13, 2026
Merged

harshsoni2024 merged 1 commit into
2.0from
backport-34934-2.0

Conversation

@harshsoni2024

Copy link
Copy Markdown
Contributor

Describe your changes:

Backport of #34934 (8aa6ad7) to 2.0. Fixes #34933 on 2.0, where it was reported (2.0.3).

A MySQL foreign key can keep its referenced column in a different case from the parent column (REFERENCES parent (id) while the column is Id). Ingestion sent that raw name in referredColumns, and the server matches column names case-sensitively. It rejected the whole child table with Invalid column name id. When the FK had been deferred to the end of the run, it dropped the FK with only a warning. Ingestion now matches each referred column to the parent table's stored column name, using the parent table it already fetched from OpenMetadata. For the analysis and the manual MySQL tests, see #34933 and #34934.

Differences from the main commit

The fix's added and removed lines are the same as in #34934. Two files conflicted, but only on surrounding lines that main has since rewritten, and 2.0 keeps its own versions of those lines:

  • common_db_source.py: 2.0 still sets database_name with an if supports_database: … else: … block, which main merged into one line in Fixes 5963: migrate BigQuery CLI E2E to v2 and fix the bugs it found #33946. The fix only moves referred_column_fqns = [] below it. MySQL's connection has no supportsDatabase, so for MySQL both versions take self.context.get().database.
  • constraints.py: get_relationship_type keeps 2.0's Dict/List signature. resolve_column_names is added above it unchanged.
  • test_common_db_source.py: applied cleanly, plus one import (model_str) that main's version of the file already had.

The fix also behaves the same on 2.0 because these match main:

  • The callers of _prepare_foreign_constraints: the per-table call and the end-of-run yield_table_constraints pass. They differ only in type annotations.
  • The server check that rejected the table (TableRepository.validateTableConstraints → EntityRepository.validateColumn).

Tests

Run on this branch, with models generated from 2.0's schemas:

  • TestPrepareForeignConstraintsReferredColumnCase: 8 passed. With 2.0's original sources, 7 fail and the exact-match case passes, as on main. All 35 tests in test_common_db_source.py pass.
  • tests/unit/topology/database and tests/unit/utils, run on 2.0 and on this branch: the only difference is the 7 new tests, which fail on 2.0 and pass here. Both runs have the same 39 failures and 54 errors, none in code this PR changes. Most come from connector packages missing in the local venv. The rest also fail on unmodified 2.0.
  • ruff check and ruff format --check on the changed files: clean. basedpyright 1.39.3 on the two source files, with 2.0's baseline and --baselinemode=discard as in static-checks: 0 errors.
  • Not completed locally: tests/integration/mysql/test_foreign_key_case.py. Both attempts stopped in fixture setup, before the test ran. On the first, the MySQL testcontainer didn't report ready within 120 s. On the second, the local OpenMetadata server was shut down during the run. The test runs in this PR's CI. On main it fails without the fix and passes with it (Fixes #34933: Match FK referred columns to the parent table's column case #34934).

Type of change:

  • Bug fix

🤖 Generated with Claude Code

…n case (#34934)

MySQL can keep a foreign key's referenced column as written in the FK
definition (`REFERENCES limitadjustmentreasons (id)`) while the parent
column is `Id`. Ingestion built referredColumns from that raw name and the
server validates referred columns case-sensitively, so it rejected the whole
child table with `Invalid column name id`, or silently dropped the FK when
it was deferred to the end of the run.

Resolve each referred column against the parent table already fetched from
OpenMetadata: exact match first, then a single case-insensitive match. Use
the resolved names for the relationship type too, which reported
MANY_TO_MANY instead of MANY_TO_ONE. A referred column that still doesn't
resolve is retried after all tables are ingested, then skipped with a
warning instead of failing the table.

Backport to 2.0: the fix's changed lines are the same as on main. The
conflicts were in surrounding lines that main has since rewritten, so 2.0
keeps its own versions of them: the typing.Dict/List signature of
get_relationship_type and the if/else that sets database_name. The unit
test file also imports model_str, which main's version already did.

(cherry picked from commit 8aa6ad7)
@harshsoni2024
harshsoni2024 requested a review from a team as a code owner October 13, 2026 07:25
@harshsoni2024
harshsoni2024 requested review from akashverma0786 and removed request for a team October 13, 2026 07:25
@harshsoni2024 harshsoni2024 added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Oct 13, 2026
@github-actions

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 Oct 13, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🟡 Medium risk · Case-insensitive foreign-key resolution alters ingested relationship metadata; a unique case-only match on a case-sensitive source could link a constraint to the wrong column.

Backport of the MySQL foreign key fix that matches referred columns to the parent table's stored column name, so case differences like id vs Id no longer cause the child table to be rejected with Invalid column name. No issues found.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

Options

Display: compact → Counting what did not apply, without listing it.

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

@sonarqubecloud

Copy link
Copy Markdown

@harshsoni2024
harshsoni2024 merged commit a337299 into 2.0 Oct 13, 2026
87 of 101 checks passed
@harshsoni2024
harshsoni2024 deleted the backport-34934-2.0 branch October 13, 2026 10:00

This branch was successfully deployed

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

Labels

Ingestion safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants