fix(oracle): restore catalog-aware constraint reflection - #31807
Conversation
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
|
The Python checkstyle failed. Please run You can install the pre-commit hooks with |
| if kw.get("oracle_resolve_synonyms", False): | ||
| rows = list( | ||
| self._get_synonyms( | ||
| connection, | ||
| schema, | ||
| [table_name], | ||
| dblink, | ||
| info_cache=kw.get("info_cache"), | ||
| ) | ||
| ) | ||
| if rows: | ||
| row = rows[0] | ||
| table_name = self.denormalize_name(row.table_name) | ||
| schema = self.denormalize_name(row.table_owner) | ||
| if row.db_link: |
There was a problem hiding this comment.
⚠️ Bug: Synonym resolution skips denormalization when no synonym found
In _prepare_constraint_args, when oracle_resolve_synonyms=True but self._get_synonyms(...) returns no rows (the table is a real table, not a synonym), table_name/schema are never denormalized and are passed to the query as the raw (typically lowercase) input. Since Oracle stores identifiers uppercase, ac.table_name = :table_name won't match and PK/UQ/FK reflection silently returns empty. Upstream SQLAlchemy always falls back to denormalize_name(...) in this case. Fix by denormalizing on the no-synonym fallback path.
Always denormalize on the no-synonym fallback, matching upstream behavior.:
def _prepare_constraint_args(self, connection, table_name, schema, **kw):
dblink = kw.get("dblink", "")
if dblink and not dblink.startswith("@"):
dblink = f"@{dblink}"
if kw.get("oracle_resolve_synonyms", False):
rows = list(
self._get_synonyms(
connection, schema, [table_name], dblink,
info_cache=kw.get("info_cache"),
)
)
if rows:
row = rows[0]
table_name = self.denormalize_name(row.table_name)
schema = self.denormalize_name(row.table_owner)
if row.db_link:
dblink = row.db_link if row.db_link.startswith("@") else f"@{row.db_link}"
return table_name, schema, dblink
table_name = self.denormalize_name(table_name)
schema = self.denormalize_name(schema or self.default_schema_name)
return table_name, schema, dblink
Was this helpful? React with 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
Backports #31676 to 2.0.
This applies catalog-aware Oracle primary-key, unique-constraint, and foreign-key reflection and preserves backing-index metadata.
Focused verification: 4 Oracle constraint-reflection tests passed.
Greptile Summary
Restores catalog-aware Oracle constraint reflection by overriding primary-key, unique-constraint, and foreign-key inspection while retaining backing-index metadata.
Confidence Score: 5/5
The pull request appears safe to merge, with no concrete changed-code failure established.
The new reflection methods preserve the expected constraint shapes, route queries through the configured Oracle catalog, and include focused coverage for the principal catalog and synonym paths.
Important Files Changed
Sequence Diagram
sequenceDiagram participant Ingestion as Oracle ingestion participant Inspector as SQLAlchemy Inspector participant Dialect as Patched OracleDialect participant Catalog as Oracle catalog Ingestion->>Inspector: Reflect table constraints Inspector->>Dialect: get_pk_constraint / get_unique_constraints / get_foreign_keys Dialect->>Dialect: Resolve synonym and normalize identifiers Dialect->>Catalog: Query configured DBA_ or ALL_ catalog views Catalog-->>Dialect: Constraint rows and backing index names Dialect-->>Inspector: SQLAlchemy reflection metadata Inspector-->>Ingestion: PK, unique, and foreign-key definitionsReviews (1): Last reviewed commit: "fix(oracle): restore catalog-aware const..." | Re-trigger Greptile