Skip to content

fix(semantic-layer): mapper honors the SemanticView ABC contract - #43886

Draft
mikebridge wants to merge 2 commits into
apache:masterfrom
mikebridge:sc-119510-mapper-abc-contract
Draft

fix(semantic-layer): mapper honors the SemanticView ABC contract#43886
mikebridge wants to merge 2 commits into
apache:masterfrom
mikebridge:sc-119510-mapper-abc-contract

Conversation

@mikebridge

Copy link
Copy Markdown
Contributor

SUMMARY

Fixes SC-119510: the semantic-layer query mapper duck-typed undeclared .metrics / .dimensions attributes on the provider view (query_object.datasource.implementation), but the superset-core SemanticView ABC declares only the abstract methods get_metrics() / get_dimensions(). A provider built strictly to the documented ABC therefore satisfies the interface yet crashes at query time — the first AttributeError fires in _validate_metrics and surfaces as an HTTP 500 {"message": "Fatal error"} on the first chart query. Explore and metadata endpoints call the methods, so a strictly-ABC provider looks healthy until a chart queries it. The shipped Snowflake/Cube/MetricFlow extensions dodge the bug only by convention (they happen to define the attributes).

The fix removes the dual contract outright, without touching the superset-core ABC: all 11 duck-typed sites across the 6 mapper functions (map_query_object, _validate_metrics, _validate_dimensions, _validate_granularity, _validate_group_limit, _validate_orderby) now call the abstract methods the mapper already requires, fetching once per function into a local. This also matches the existing convention elsewhere (superset/semantic_layers/models.py already calls implementation.get_metrics()).

Test strategy makes the whole suite the regression proof:

  • MockSemanticView now stores its sets privately and exposes only the ABC surface — with the fix reverted, 34 mapper tests fail with the exact defect signature.
  • A new AbcOnlyView fixture subclasses the real SemanticView ABC (methods only, name-mangled storage) and pins the end-to-end validate+map path that used to 500 (test_abc_only_provider_validates_and_maps).
  • Five tests that hand-rolled mocker.Mock() implementations with attribute assignment now build real MockSemanticView instances.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend contract fix. Before: AttributeError: 'AbcOnlyView' object has no attribute 'metrics' → HTTP 500 on POST /api/v1/chart/data. After: the query maps and executes.

TESTING INSTRUCTIONS

python -m pytest tests/unit_tests/semantic_layers -q   # 437 passed

Reverted-fix control: git stash push -- superset/ && python -m pytest tests/unit_tests/semantic_layers/mapper_test.py -q → 34 failed; git stash pop.

ADDITIONAL INFORMATION

🤖 Generated with Claude Code

https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW

The query mapper read bare .metrics/.dimensions attributes off the
provider view (query_object.datasource.implementation), but the
superset-core SemanticView ABC declares only the abstract
get_metrics()/get_dimensions() methods — no such attributes. A provider
built strictly to the documented ABC satisfied the interface yet
crashed at query time: the first AttributeError fired in
_validate_metrics and surfaced as HTTP 500 'Fatal error' on the first
chart query, while Explore/metadata endpoints (which call the methods)
looked healthy. Shipped providers dodged it only by convention
(SC-119510, found during SC-106828 Phase-1 validation).

All 11 duck-typed sites across the 6 mapper functions now call the
abstract methods, fetched once per function; the dual contract is gone
without touching the superset-core ABC.

Tests: MockSemanticView now stores its sets privately and exposes ONLY
the ABC surface, so the entire mapper suite exercises the method
contract (with the fix reverted, 34 tests fail); a strict
SemanticView-subclass fixture (AbcOnlyView) pins the end-to-end
validate+map path that used to 500.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
Three-lens round (clean-code, tidy-first, python), converged items:

- test_validate_metrics_adhoc_error: replace the dead private-attribute
  writes on a bare Mock (pre-existing dead lines the rename made
  misleading) with a real MockSemanticView, matching the other converted
  fixtures
- mapper comment made timeless (no incident narrative or tracker id);
  test docstrings cite the upstream PR instead of the internal ticket
- AbcOnlyView documents why its storage is name-mangled (guarantees no
  duck-typable name exists), so a future cleanup cannot weaken the
  fixture

Deferred with a ticket: per-request metadata call multiplicity
(fetch-once threading through the validators) and the annotation-only
features/name attributes on the superset-core ABC.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
@codecov

codecov Bot commented Sep 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.45%. Comparing base (d9b201d) to head (02044ba).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #43886   +/-   ##
=======================================
  Coverage   79.45%   79.45%           
=======================================
  Files        2895     2895           
  Lines      168167   168170    +3     
  Branches    38995    38995           
=======================================
+ Hits       133624   133627    +3     
  Misses      32044    32044           
  Partials     2499     2499           
Flag Coverage Δ
hive 37.77% <0.00%> (-0.01%) ⬇️
mysql 57.48% <0.00%> (-0.01%) ⬇️
postgres 57.51% <0.00%> (-0.01%) ⬇️
presto 39.66% <0.00%> (-0.01%) ⬇️
python 83.87% <100.00%> (+<0.01%) ⬆️
sqlite 57.21% <0.00%> (-0.01%) ⬇️
unit 74.40% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant