fix(semantic-layer): mapper honors the SemanticView ABC contract - #43886
Draft
mikebridge wants to merge 2 commits into
Draft
fix(semantic-layer): mapper honors the SemanticView ABC contract#43886mikebridge wants to merge 2 commits into
mikebridge wants to merge 2 commits into
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
Fixes SC-119510: the semantic-layer query mapper duck-typed undeclared
.metrics/.dimensionsattributes on the provider view (query_object.datasource.implementation), but the superset-coreSemanticViewABC declares only the abstract methodsget_metrics()/get_dimensions(). A provider built strictly to the documented ABC therefore satisfies the interface yet crashes at query time — the firstAttributeErrorfires in_validate_metricsand 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.pyalready callsimplementation.get_metrics()).Test strategy makes the whole suite the regression proof:
MockSemanticViewnow stores its sets privately and exposes only the ABC surface — with the fix reverted, 34 mapper tests fail with the exact defect signature.AbcOnlyViewfixture subclasses the realSemanticViewABC (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).mocker.Mock()implementations with attribute assignment now build realMockSemanticViewinstances.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend contract fix. Before:
AttributeError: 'AbcOnlyView' object has no attribute 'metrics'→ HTTP 500 onPOST /api/v1/chart/data. After: the query maps and executes.TESTING INSTRUCTIONS
python -m pytest tests/unit_tests/semantic_layers -q # 437 passedReverted-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