Skip to content

Fixes 32508: [2.0] Backport profiler ORM column name fix (#32805) - #37295

Merged
TeddyCr merged 5 commits into
open-metadata:2.0from
TeddyCr:backport/32805-2.0
Nov 9, 2026
Merged

TeddyCr merged 5 commits into
open-metadata:2.0from
TeddyCr:backport/32805-2.0

Conversation

@TeddyCr

@TeddyCr TeddyCr commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes #32508

Backports #32805 (merged commit f02e818119fd49252c27afe1b324044c64857cf4) to 2.0.

The profiler now maps columns beginning with __ or _sa_ through safe, unique Python attribute names. This preserves the first column's synthetic primary key and prevents these columns from being silently omitted from profiling. The source column names and existing SQLAlchemy column keys remain unchanged.

The backport resolves conflicts in converter/base.py by retaining 2.0's Optional annotations and build_orm_col(idx, col, table.serviceType) call. It does not bring in main's separate build_orm_col_keys helper or change 2.0's lowercase column-key behavior. Both upstream regression tests are preserved unchanged.

Type of change:

  • Bug fix

High-level design:

Not applicable — a two-file backport of an existing bug fix. No schema, API, migration, configuration, or UI changes.

Tests:

Use cases covered

  • A __hevo_id first column remains mapped and retains the synthetic primary key.
  • A later _sa_special column remains present in the mapped table.
  • Normal column names that collide with remapped names receive distinct attributes.
  • Existing Snowflake quoting, reserved metadata, and MONEY/BIT conversion tests still pass.
  • Real SQLite insert/select smoke checks preserve column names, keys, primary keys, and values for both column orders of __hevo_id/om_col___hevo_id and metadata/metadata_.

Unit tests

  • Updated: ingestion/tests/unit/observability/profiler/test_converter.py.
  • Python 3.11.13, SQLAlchemy 2.0.55; models generated from the 2.0 worktree using scripts/datamodel_generation.py and make py_antlr.
  • Confirmed the imported test_dunder_prefixed_columns_are_mapped fails on the unpatched 2.0 converter with could not assemble any primary key columns (1 failed, 10 deselected).
  • With the backport: 11 passed:
    cd ingestion
    PYTHONPATH="$PWD/src" ../env/bin/python -m pytest -p no:rerunfailures \
      -c pyproject.toml tests/unit/observability/profiler/test_converter.py \
      -q --tb=short --cov=metadata.profiler.orm.converter.base --cov-report=term-missing
  • New _safe_orm_attr helper coverage: 100% lines (8/8) and branches (6/6). The focused run reports 43.7% line coverage for the entire converter module; full-module 90% coverage was not established.
  • The initial pytest attempt stopped during optional pytest-rerunfailures initialization because the sandbox disallows its localhost socket. Disabling that retry plugin allowed normal test execution; no test was skipped.
  • Focused Ruff check/format: passed for both changed files. Commit hooks also passed.
  • Focused type check: 0 errors, 0 warnings, 0 notes:
    cd ingestion
    PYTHONPATH="$PWD/src" ../env/bin/basedpyright -p pyproject.toml \
      --baselinefile .basedpyright/baseline.json --baselinemode=discard \
      --pythonpath ../env/bin/python src/metadata/profiler/orm/converter/base.py
  • git diff upstream/2.0...HEAD --check: passed.

Backend integration tests

Not applicable — no Java or backend API changes.

Ingestion integration tests

6 real SQLite insert/select scenarios passed, using fresh in-memory databases and the backported converter. No SQLAlchemy internals were mocked.

The existing server-backed ingestion/tests/integration/orm_profiler/test_converter.py and broader profiler suites remain pending. No OpenMetadata server was available at localhost:8585 (the version endpoint connection failed); they were not run. This PR records focused verification, not full merge-readiness coverage.

Playwright (UI) tests

Not applicable — no UI changes.

Manual testing performed

Ran a Python smoke script against the worktree:

  1. Construct SQLite table entities with columns [__hevo_id, normal_col, _sa_special] and [normal_col, __hevo_id, _sa_special].
  2. Repeat with [__hevo_id, om_col___hevo_id] and its reverse, then [metadata, metadata_] and its reverse.
  3. Convert each entity with a fresh SQLAlchemy MetaData; assert all original names and keys are present and the first column remains the sole primary key.
  4. Create each table in a fresh in-memory SQLite database, insert distinct integer values, select through the generated ORM class, and assert every value round-trips under its original column name.
  5. All six cases passed.

UI screen recording / screenshots:

Not applicable — no UI changes.

Checklist:

  • Read the repository contribution guidance.
  • PR title follows Fixes <issue-number>: <short explanation>.
  • Linked the issue with Fixes #32508.
  • Preserved upstream comments explaining the SQLAlchemy workaround.
  • Preserved upstream regression tests and listed actual verification results.
  • Reviewed committed backport fb1d989ce6c7ea2e1472fa8b6be6f8cde40e81a5 against REVIEW.md; no unanswered important findings.
  • JSON Schema/migrations: not applicable.
  • UI recording: not applicable.
  • New decision record: not applicable — preserves an already merged fix.
  • Collate counterpart: not applicable — Python profiler backport in this repository.
  • Full server-backed profiler integration suite and full-module coverage remain pending as described above.

Summary by Gitar

  • Column name resolution:
    • Data quality column-existence and match-set validators now read source names via col.name instead of ORM keys
    • Profiler ColumnNames metric and table metric computers now report source names via col.name
  • New tests:
    • Added test_column_names.py covering metrics and validators with dunder, reserved, and mixed-case names

This will update automatically on new commits.

Review follow-up: source column names

Addresses the column-name consumer review comment in commit 51756fa36b72b39ff7b71a9d8390de5b5a50e38a. The matching main fix is #37326.

Profiling and the two table column-name validators now use Column.name rather than mapped attribute keys. Includes the common/catalog, TimescaleDB, Informix and stats-based paths. The converter regression now asserts the reported metric, and a new test_column_names.py exercises remapped/reserved names, mixed-case source names, collisions, ordered/unordered sets, missing names and empty-column errors.

Focused verification on this follow-up:

  • 95 passed across tests/unit/observability/profiler/test_column_names.py, test_converter.py and test_table_metric_computer.py.
  • 3 passed, 68 deselected in tests/unit/observability/data_quality/test_validations_databases.py -k 'column_name_to_exist or column_to_match_set'.
  • Both commands ran from ingestion/ with PYTHONPATH="$PWD/src" ../env/bin/python -m pytest -p no:rerunfailures -c pyproject.toml ... -q --tb=short.
  • Test-first reproduction: 12 failures, 16 passes before the consumer fix. The first post-fix run had 92 passes, 1 failure because the new unordered test passed a string boolean unsupported by 2.0's existing parser; that regression now uses the supported default unordered mode. Final runs above pass.
  • Coverage measured with pytest-cov for all four changed source modules: both validators 100% lines/branches; column_names.py 12.2%, table_metric_computer.py 33.6% in this focused run. All added statements measured by coverage executed; full-module 90% remains pending.
  • Focused Ruff check/format, basedpyright (0 errors, 0 warnings, 0 notes), commit/push hooks and git diff --check: passed.
  • Independent review of the committed follow-up against REVIEW.md: no blocking findings.
  • Broader server-backed and database-specific ingestion integration tests remain pending. No OpenMetadata server was listening on localhost:8585.

Backport open-metadata#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 open-metadata#32508.
@TeddyCr
TeddyCr requested a review from a team as a code owner November 6, 2026 18:58
@TeddyCr
TeddyCr requested review from mohittilala and removed request for a team November 6, 2026 18:58
@github-actions

github-actions Bot commented Nov 6, 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.

@github-actions github-actions Bot added Ingestion safe to test Add this label to run secure Github workflows on PRs labels Nov 6, 2026
@sonarqubecloud

sonarqubecloud Bot commented Nov 6, 2026

Copy link
Copy Markdown

@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 6, 2026
@Vdivy

Vdivy commented Nov 7, 2026

Copy link
Copy Markdown

This also breaks the data-quality test suite runner on 2.0.6, not only the profiler. Every test on a table whose first column starts with __ errors with Mapper ... could not assemble any primary key columns, so none of that table's tests run. A later column starting with __ is also left out of the mapped table.

Reproduced with openmetadata-ingestion==2.0.6 and the Trino connector, on Iceberg aggregate tables whose first column is __time. In the meantime we prefix those attribute names before the ORM class is built and keep the column names. Looking forward to this backport in a 2.0.x release.

@TeddyCr TeddyCr added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 9, 2026
@TeddyCr TeddyCr closed this Nov 9, 2026
@TeddyCr TeddyCr reopened this Nov 9, 2026
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 9, 2026
@github-actions github-actions Bot added safe to test Add this label to run secure Github workflows on PRs and removed safe to test Add this label to run secure Github workflows on PRs labels Nov 9, 2026
@gitar-bot

gitar-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🟡 Medium risk · Remapping reserved ORM attributes and reporting source column names changes profiler and data-quality behavior; incorrect mapping could misreport columns or validation results.

Backports the profiler ORM fix so columns starting with __ or _sa_ map through safe, unique attribute names, preserving the synthetic primary key and keeping these columns in profiling. Column-name metrics and data quality validators now read source names via col.name, resolving the previously open leak of remapped attribute names. No open issues remain.

✅ 1 closed
✅ Bug: Remapped attr names leak into columnNames metric and column-name DQ tests

📄 ingestion/src/metadata/profiler/orm/converter/base.py:49-63 📄 ingestion/src/metadata/profiler/orm/converter/base.py:171-176 📄 ingestion/tests/unit/observability/profiler/test_converter.py:236-243
SQLAlchemy's Mapper.c (what inspect(orm).c returns) is keyed by the mapped attribute name. It is not keyed by Column.key/Column.name. With this change, a column __hevo_id is mapped under om_col___hevo_id, so these places now report the synthetic name instead of the real one:

  • ColumnNames.fn (profiler/metrics/static/column_names.py:95)
  • table_metric_computer.py:169,1024
  • tableColumnToMatchSet / tableColumnNameToExist (data_quality/validations/table/sqlalchemy/*.py)

The result: the columnNames table metric is wrong, and a tableColumnNameToExist/tableColumnToMatchSet test that expects __hevo_id fails. This contradicts the docstring's claim that 'the profiler still addresses columns by their original name'. The new test only checks __table__.columns, so it misses this.

Fix: have those consumers build names from col.name for col in inspect(orm).c (or orm.__table__.c) instead of .c.keys(). Also add an assertion on the reported column names to the test.

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

@TeddyCr
TeddyCr merged commit 31c20e9 into open-metadata:2.0 Nov 9, 2026
41 of 49 checks passed

This branch had an error being deployed

1 failed 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.

3 participants