Repository navigation
fix(profiler): remap dunder/\_sa\_ column names to avoid SQLAlchemy 2.x declarative filter - #32805
Conversation
….x declarative filter SQLAlchemy 2.x's declarative scan discards any class attribute whose name matches ^(?:__|_sa_) (see decl_base._match_exclude_dunders). Columns stored under such names are silently absent from the mapped Table; when the dropped column is first it also carries the synthetic primary key, raising: Mapper could not assemble any primary key columns for mapped table ometa_to_sqa_orm now uses a _safe_orm_attr() helper that prefixes dunder/ _sa_-named columns with 'om_col_' for the class-attribute key only. Column.name and Column.key are unchanged, so the profiler still addresses columns by their original names. This subsumes and generalises the existing SQA_RESERVED_ATTRIBUTES rename (which appended a trailing underscore for 'metadata'). Fixes open-metadata#32508.
❌ 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 |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
…_orm_attr Previously the `while candidate in existing` loop only ran for reserved and dunder/`_sa_`-prefixed column names; normal names were returned immediately without checking `existing`. This meant a normal column literally named `om_col___hevo_id` and a dunder column `__hevo_id` (remapped to the same key) would collide, silently overwriting the first column — the exact silent-drop failure this PR fixes. Move `candidate = name` into the shared path so the collision check always runs, and add a unit test covering this contrived but valid edge case. Addresses gitar-bot suggestion on PR open-metadata#32805. Prepared with AI assistance (Claude Code, Anthropic), reviewed for correctness before submission.
|
Addressed the edge case raised by gitar-bot (collision between a normal column and a remapped dunder key):
Prepared with AI assistance (Claude Code, Anthropic), reviewed for correctness before submission. |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
|
The Python checkstyle failed. Please run You can install the pre-commit hooks with |
|
Hi there 👋 Thanks for your contribution! The OpenMetadata team will review the PR shortly! Once it has been labeled as Let us know if you need any help! |
Code Review ✅ Approved 1 resolved / 1 findingsFixes SQLAlchemy 2.x silently dropping columns with ✅ 1 resolved✅ Edge Case: Unrenamed column can collide with a remapped dunder key
OptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
f02e818
…7295) * fix(profiler): backport safe ORM attributes to 2.0 Backport #32805 (f02e818) to 2.0. Keep the 2.0 build_orm_col signature and existing column-key behavior while preserving excluded column names and resolving attribute-name collisions. Fixes #32508. * Fix profiler and data quality source column names



Summary
Fixes #32508.
Columns whose names begin with
__or_sa_are silently dropped by SQLAlchemy 2.x's declarative scan (decl_base._match_exclude_dunders).ometa_to_sqa_ormbuilds the ORM class by passing column names as class-attribute keys, so any such column never reaches the mappedTable. When it is the first column (the onebuild_orm_colmarks as the synthetic primary key), SQLAlchemy raises a hard mapper error:Managed ELT tools such as Hevo prefix bookkeeping columns with
__(__hevo_id,__hevo__ingested_at). Whether a table breaks depends only on whether such a column comes first in the entity's column list.Change
ometa_to_sqa_ormnow calls a_safe_orm_attr()helper before using a column name as the class-attribute key:normal_colnormal_col(unchanged)normal_col/normal_colmetadatametadata_(existing behaviour)metadata/metadata__hevo_idom_col___hevo_id(new)__hevo_id/__hevo_id_sa_specialom_col__sa_special(new)_sa_special/_sa_specialColumn.nameandColumn.keyare unchanged, soprofiler_interface.py's__table__.columns[column.key]lookups continue to work.Collisions introduced by the renaming are resolved by appending underscores (same pattern as the existing
SQA_RESERVED_ATTRIBUTESrename).Test
test_dunder_prefixed_columns_are_mappedintest_converter.pyverifies:__hevo_id,normal_col,_sa_special) appear inorm.__table__.columnsunder their original names.__hevo_id(index 0, the synthetic PK) is the sole primary-key column — confirming that the crash path is closed.Checklist
Column.nameorColumn.key— profiler column-lookup paths are unaffected