Repository navigation
fix(semantic-layer): validate views before creation - #45287
Conversation
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #45287 +/- ##
==========================================
+ Coverage 83.56% 83.57% +0.01%
==========================================
Files 3048 3049 +1
Lines 199836 200001 +165
Branches 46613 46652 +39
==========================================
+ Hits 166984 167149 +165
Misses 29610 29610
Partials 3242 3242
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:
|
CodeAnt PR Risk: Medium Risk
Assessed commit: |
A serialized configuration that isn't a JSON object raised JSONDecodeError from validate(), which surfaced as a generic create failure. Return the per-view SemanticViewInvalidError instead, before the provider lookup. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Re CodeAnt's risk note on Before this change it didn't abort the request: the |
aminghadersohi
left a comment
There was a problem hiding this comment.
Not ready to merge.
Please remove the private tracker IDs from the PR body and commit messages before merge.
| Superset reports that the view may not exist or the semantic layer may be | ||
| unreachable, and does not add it. Other valid views in the same request can still |
There was a problem hiding this comment.
The Add Semantic View dialog replaces 422 responses with a generic toast and shows only names on partial success, so users never see this reason. Limit this claim to the API response.
| Superset reports that the view may not exist or the semantic layer may be | |
| unreachable, and does not add it. Other valid views in the same request can still | |
| the API reports that the view may not exist or the semantic layer may be | |
| unreachable, and does not add it. Other valid views in the same request can still |
There was a problem hiding this comment.
Updated in d93a8e4: the docs now explicitly say “the API reports”. The modal still uses a generic toast for a 422 and names only on partial success. I’ve proposed a separate follow-up to surface result.errors[].error in both paths; no UI behavior changes in this PR.
gabotorresruiz
left a comment
There was a problem hiding this comment.
Hi @mikebridge, thanks for this one. No defect found on my side: I ran the semantic layer suites and drove every failure path against a stub provider, and nothing from the layer configuration or the provider exception reaches the response or the logs on any of them. Three non-blocking comments inline.
Holding off on a formal approval only because unit-tests (current), the docker builds and the postgres suites are still running on b4f6d704 (pre-commit, babel-extract and Analyze (python) have passed), and because @aminghadersohi's docs comment is still open.
| name, configuration | ||
| ) | ||
| except Exception as ex: # pylint: disable=broad-except | ||
| logger.warning("Semantic view lookup failed: %s", type(ex).__name__) |
There was a problem hiding this comment.
Not a blocker. The type does separate a ConnectionError from a provider-side AttributeError, which is good, but there is no layer uuid and no view name on this line, so a burst of these doesn't say which layer is down. The same provider call on the discovery path (superset/semantic_layers/api.py:898) logs str(ex) with exc_info=True, so provider exception text already reaches the logs on the request the Add dialog makes right before this one. Could we add the identifiers here? Both are already echoed in the response, so neither is new exposure.
| logger.warning("Semantic view lookup failed: %s", type(ex).__name__) | |
| logger.warning( | |
| "Semantic view lookup failed for layer %s, view %s: %s", | |
| layer_uuid, | |
| name, | |
| type(ex).__name__, | |
| ) |
There was a problem hiding this comment.
Added the layer UUID and view name in d93a8e4, while keeping only the exception type and no provider traceback. The regression test asserts the exact warning and retains the checks that provider exception text does not appear in logs or responses.
There was a problem hiding this comment.
Confirmed, thanks. On d93a8e4c65 the line comes out as Semantic view lookup failed for layer <uuid>, view orders: ConnectionError, where b4f6d7048e gave only Semantic view lookup failed: ConnectionError. The exact equality assertion on caplog.messages is the right shape too: swapping type(ex).__name__ for ex fails the test, so the secret free form is pinned rather than just sampled.
| _("The view configuration must be a JSON object.") | ||
| ) | ||
| try: | ||
| view: SemanticViewABC | None = layer.implementation.get_semantic_view( |
There was a problem hiding this comment.
More a question about the bulk shape than a blocker. views is only checked for non-empty at superset/semantic_layers/api.py:379, and each item now pays its own provider round trip, so the request time scales with the item count. I couldn't find a timeout on get_semantic_view anywhere under superset/semantic_layers/, so a hung provider holds the worker and the metadata connection for as long as the provider's own socket waits, once per item. The known limitation note compares this to the discovery endpoint, but that one is a single call per request.
Also, because the lookup deliberately runs before the uniqueness check, re-submitting an already added view now pays the round trip too. Both of those feel like the right trade for the fix, so mostly I'm asking whether views is worth bounding here or whether that belongs in its own change.
There was a problem hiding this comment.
Agreed: this is one lookup per item, so the discovery-endpoint comparison does not capture the bulk multiplier. Lookup stays before uniqueness to avoid putting a remote round trip between the uniqueness check and insert; an already-added view therefore also pays that lookup. This PR accepts that latency and metadata-connection hold. I’ve proposed a separate follow-up to bound views and define an enforceable provider lookup timeout, including retry/partial-success behavior. A host-side wait timeout alone would not necessarily cancel the provider operation or release its resources, so I’m leaving request handling unchanged here.
There was a problem hiding this comment.
That reasoning holds for me, in particular that a host side wait would not necessarily cancel the provider's work or release its resources. Happy to take the views bound and an enforceable lookup timeout as their own change.
|
|
||
| When adding a semantic view, Superset asks the provider to look up its name with | ||
| the submitted configuration before saving it. If lookup fails or returns no view, | ||
| Superset reports that the view may not exist or the semantic layer may be |
There was a problem hiding this comment.
Agreed with @aminghadersohi here, and one more data point for it: when nothing is created the response is 422, parseResponse rejects on !response.ok, and AddSemanticViewModal.tsx:650 falls into the generic An error occurred while adding semantic views toast. So this reason isn't rendered in either shape today, not only on partial success where the toast carries just the names. Worth surfacing result.errors[].error in the modal as a follow-up so the new string reaches someone?
There was a problem hiding this comment.
Thanks for tracing both paths. The docs are limited to the API response in d93a8e4. I’ve proposed a follow-up for the modal to render result.errors[].error for both all-failed 422 responses and partial-success responses, with a fallback when the response has no usable per-item error. That follow-up is a local proposal, not an additional change in this PR.
There was a problem hiding this comment.
Reads right to me now. I checked the paragraph against both shapes again and "the API reports" is accurate: the partial success 201 body carries result.errors[].error per item, and the all failed case returns the same string in a 422. parseResponse.ts:42 still rejects before the modal can read either, so no UI surface renders it. Good with the modal change being its own follow-up.
gabotorresruiz
left a comment
There was a problem hiding this comment.
Hi @mikebridge, the delta does exactly what the threads asked for, so this is an approve. I re-drove all four lookup paths against a stub provider at DEBUG and the new warning stays clean: nothing from the layer configuration or the provider exception reaches the responses or the logs. CI is green on d93a8e4c65, including the two test jobs that were still running when I held off last time. My approval is on the code; I'm leaving the PR body cleanup @aminghadersohi raised to his thread. One non-blocking question inline.
| type(ex).__name__, | ||
| ) | ||
| view = None | ||
| if view is None: |
There was a problem hiding this comment.
Not a blocker, and this could ride along with the follow-up you already have planned. The warning above only covers the raising half: a provider that handles its own connection error and returns None lands here instead, and neither the command nor the SemanticViewInvalidError handler at api.py:399 logs anything on that path, so the 422 goes out with no line naming the layer. Worth a matching logger.info here, or do you see the two cases as different enough that the silence is right?
There was a problem hiding this comment.
Added in 5842d57: the no-view rejection logs an INFO message with the layer UUID and view name, including when the provider returns None. The exception path keeps its type-only warning and also emits that INFO message. The red-first test_create_semantic_view_lookup_failure[None] pins the exact INFO message and level; the exception cases pin both messages and still check that provider exception text and tracebacks are absent. No request or persistence behavior changed.
SUMMARY
TL;DR: Validate a semantic view through the same provider lookup used by saved views before adding it.
Background: Add Semantic View discovers available views using the selected layer and runtime configuration.
Problem: The create command checked access and duplicate names but could save a view that the provider no longer offered. The problem surfaced only when someone tried to use that saved view.
What this changes:
The detailed design follows.
JSON-string configurations accepted by the command are decoded for both lookup and uniqueness checks. The lookup is
get_semantic_view(name, configuration), matching persisted-view resolution and preserving providers' legacy/default configurations. Providers that construct views without a live request do not gain a connectivity probe. Cross-API identity consolidation is outside this bounded fix.Known limitation: There is one lookup per item, and the metadata read connection remains held during that lookup, as with the discovery endpoint. This is accepted for this bounded change; there is no session-lifetime redesign, per-request discovery cache, or SDK/provider error-contract change. Lookup precedes uniqueness so no remote call widens the check-to-insert window. Providers need not distinguish a nonexistent view from an unreachable layer, hence the single honest validation message.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable: backend validation only.
TESTING INSTRUCTIONS
With
SEMANTIC_LAYERSenabled and an existing provider-backed layer:POST /api/v1/semantic_view/; the item reports the honest validation message and no record is created (422 when no items succeed).Regression tests cover lookup-before-uniqueness ordering, default and JSON-string configuration compatibility, exact missing/failure versus duplicate messages, HTTP 422 responses, and absence of provider secrets from responses and logs. All 12 new regression cases failed before this follow-up.
Local validation: 155 focused tests passed; changed-file pre-commit hooks, including MyPy, passed. The translation template matches fresh extraction. Full service-free unit suite at
234d189fce: 27,283 passed, 11 failed, 49 skipped, 2 xfailed. All eleven failed-test IDs exactly match the accepted baseline; no additional failures. Independent Claude delta review approved the exact tree (no blocker/high/medium findings).Unexecuted/known: Live-provider and browser checks were not run; CI remains pending. Three failures match the documented local ARM longdouble/PATH baseline. The other eight MCP dateutil/DST failures reproduced identically on base
0ce9b6ca46in the same environment and were accepted as baseline for this branch. No failing files are changed here.ADDITIONAL INFORMATION
SEMANTIC_LAYERSImplementation and local review assisted by Codex.