fix(oracle): restore catalog-aware constraint reflection - #31809
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 path skips name denormalization when no synonym found
When oracle_resolve_synonyms=True but _get_synonyms returns no rows (i.e. the object is a regular table, not a synonym), _prepare_constraint_args leaves table_name/schema as the normalized (lowercase) values received from the inspector and never calls denormalize_name. The constraint query then matches ac.table_name = :table_name/ac.owner = :owner against Oracle's uppercase data dictionary and returns nothing, so PK/unique/FK constraints silently disappear. SQLAlchemy's original _prepare_reflection_args always falls back to denormalize_name(table_name) and denormalize_name(schema or default_schema_name) when no synonym is resolved. Add the same fallback in the if rows: branch's else path.
Denormalize table/schema even when synonym resolution yields no rows.:
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}"
else:
table_name = self.denormalize_name(table_name)
schema = self.denormalize_name(schema or self.default_schema_name)
else:
Was this helpful? React with 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
Backports #31676 to 1.13.
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
The PR restores catalog-aware Oracle constraint reflection by overriding primary-key, unique-constraint, and foreign-key reflection while preserving backing-index metadata.
DBA_*orALL_*Oracle catalog views for constraint queries.Confidence Score: 5/5
The PR appears safe to merge; no concrete changed-code defect or security issue was identified.
The new reflection methods preserve the expected constraint shapes, select from the configured Oracle catalog, handle synonym targets before querying, and are covered by focused regression tests.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(oracle): restore catalog-aware const..." | Re-trigger Greptile
Context used: