You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "mikebridge (via GitHub)" <gi...@apache.org> on 2026/10/14 17:27:49 UTC

[PR] fix(semantic-layer): validate views before creation [superset]

mikebridge opened a new pull request, #45287:
URL: https://github.com/apache/superset/pull/45287

   ### SUMMARY
   
   **TL;DR:** Check that a semantic view is still available from its provider 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:** Repeat provider discovery using the submitted configuration before saving. Reject an unavailable name with a typed validation error, and handle discovery failures through the existing create-error path. Bulk requests keep their per-item results, so valid siblings can still be created.
   
   JSON-string configurations accepted by the command are decoded for both uniqueness checks and discovery. This checks discovery membership; providers that construct views without a live query do not gain a connectivity probe. Cross-API identity consolidation is outside this bounded fix.
   
   [SC-126722](https://app.shortcut.com/preset/story/126722)
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   Not applicable: backend validation only.
   
   ### TESTING INSTRUCTIONS
   
   With `SEMANTIC_LAYERS` enabled and an existing provider-backed layer:
   
   1. Add a discovered view with its runtime configuration; it is created.
   2. Submit an unavailable view name to `POST /api/v1/semantic_view/`; the item fails with its name and no record is created (422 when no items succeed).
   3. Make provider discovery fail; the item uses the existing generic create-failure response and is not saved.
   
   Regression tests cover command validation, JSON-string configuration compatibility, HTTP 422 responses, and no DAO writes on validation/provider failures. The new command cases failed before the fix.
   
   Local validation: 150 focused tests passed; changed-file pre-commit hooks, including MyPy, passed. Full service-free unit suite at `ba248a1f90`: 27,278 passed, 11 failed, 49 skipped, 2 xfailed.
   
   **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 `0ce9b6ca46` in the same environment and were accepted as baseline for this branch (tracked in [SC-126726](https://app.shortcut.com/preset/story/126726)). No failing files are changed here.
   
   ### ADDITIONAL INFORMATION
   
   - [x] Has associated issue: [SC-126722](https://app.shortcut.com/preset/story/126722)
   - [x] Required feature flags: `SEMANTIC_LAYERS`
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   Implementation and local review assisted by Codex.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(semantic-layer): validate views before creation [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #45287:
URL: https://github.com/apache/superset/pull/45287#issuecomment-6181679890

   ## CodeAnt PR Risk: Medium Risk
   
   - The PR needs attention before merging because malformed configuration strings may fail outside the provider lookup error handling.
   - Confirm that invalid JSON is returned as a client validation error rather than an unhandled server error.
   
   **Assessed commit:** `234d189fcef0`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(semantic-layer): validate views before creation [superset]

Posted by "mikebridge (via GitHub)" <gi...@apache.org>.
mikebridge commented on code in PR #45287:
URL: https://github.com/apache/superset/pull/45287#discussion_r4287846996


##########
docs/docs/using-superset/semantic-layer-connections.mdx:
##########
@@ -61,3 +61,9 @@ keeps dependent choices unavailable until that source is filled. Clearing an
 optional dependency can load choices for the empty state instead. Semantic
 views listed for an earlier dependency are discarded, and views cannot be added
 while dependent choices are loading.
+
+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
+unreachable, and does not add it. Other valid views in the same request can still

Review Comment:
   Updated in d93a8e4c65: 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.



##########
superset/commands/semantic_layer/create.py:
##########
@@ -108,7 +111,36 @@ def validate(self) -> None:
             raise SemanticViewForbiddenError()
 
         name: str = self._properties.get("name", "")
-        configuration: dict[str, Any] = self._properties.get("configuration") or {}
+        raw_configuration: dict[str, Any] | str = (
+            self._properties.get("configuration") or {}
+        )
+        try:
+            configuration: Any = (
+                json.loads(raw_configuration)
+                if isinstance(raw_configuration, str)
+                else raw_configuration
+            )
+        except ValueError:
+            configuration = None
+        if not isinstance(configuration, dict):
+            raise SemanticViewInvalidError(
+                _("The view configuration must be a JSON object.")
+            )
+        try:
+            view: SemanticViewABC | None = layer.implementation.get_semantic_view(
+                name, configuration
+            )
+        except Exception as ex:  # pylint: disable=broad-except
+            logger.warning("Semantic view lookup failed: %s", type(ex).__name__)

Review Comment:
   Added the layer UUID and view name in d93a8e4c65, 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.



##########
superset/commands/semantic_layer/create.py:
##########
@@ -108,7 +111,36 @@ def validate(self) -> None:
             raise SemanticViewForbiddenError()
 
         name: str = self._properties.get("name", "")
-        configuration: dict[str, Any] = self._properties.get("configuration") or {}
+        raw_configuration: dict[str, Any] | str = (
+            self._properties.get("configuration") or {}
+        )
+        try:
+            configuration: Any = (
+                json.loads(raw_configuration)
+                if isinstance(raw_configuration, str)
+                else raw_configuration
+            )
+        except ValueError:
+            configuration = None
+        if not isinstance(configuration, dict):
+            raise SemanticViewInvalidError(
+                _("The view configuration must be a JSON object.")
+            )
+        try:
+            view: SemanticViewABC | None = layer.implementation.get_semantic_view(

Review 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.



##########
docs/docs/using-superset/semantic-layer-connections.mdx:
##########
@@ -61,3 +61,9 @@ keeps dependent choices unavailable until that source is filled. Clearing an
 optional dependency can load choices for the empty state instead. Semantic
 views listed for an earlier dependency are discarded, and views cannot be added
 while dependent choices are loading.
+
+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

Review Comment:
   Thanks for tracing both paths. The docs are limited to the API response in d93a8e4c65. 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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(semantic-layer): validate views before creation [superset]

Posted by "mikebridge (via GitHub)" <gi...@apache.org>.
mikebridge commented on code in PR #45287:
URL: https://github.com/apache/superset/pull/45287#discussion_r4289624381


##########
superset/commands/semantic_layer/create.py:
##########
@@ -108,7 +111,41 @@ def validate(self) -> None:
             raise SemanticViewForbiddenError()
 
         name: str = self._properties.get("name", "")
-        configuration: dict[str, Any] = self._properties.get("configuration") or {}
+        raw_configuration: dict[str, Any] | str = (
+            self._properties.get("configuration") or {}
+        )
+        try:
+            configuration: Any = (
+                json.loads(raw_configuration)
+                if isinstance(raw_configuration, str)
+                else raw_configuration
+            )
+        except ValueError:
+            configuration = None
+        if not isinstance(configuration, dict):
+            raise SemanticViewInvalidError(
+                _("The view configuration must be a JSON object.")
+            )
+        try:
+            view: SemanticViewABC | None = layer.implementation.get_semantic_view(
+                name, configuration
+            )
+        except Exception as ex:  # pylint: disable=broad-except
+            logger.warning(
+                "Semantic view lookup failed for layer %s, view %s: %s",
+                layer_uuid,
+                name,
+                type(ex).__name__,
+            )
+            view = None
+        if view is None:

Review Comment:
   Added in 5842d575b3: 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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(semantic-layer): validate views before creation [superset]

Posted by "gabotorresruiz (via GitHub)" <gi...@apache.org>.
gabotorresruiz commented on code in PR #45287:
URL: https://github.com/apache/superset/pull/45287#discussion_r4288823641


##########
superset/commands/semantic_layer/create.py:
##########
@@ -108,7 +111,41 @@ def validate(self) -> None:
             raise SemanticViewForbiddenError()
 
         name: str = self._properties.get("name", "")
-        configuration: dict[str, Any] = self._properties.get("configuration") or {}
+        raw_configuration: dict[str, Any] | str = (
+            self._properties.get("configuration") or {}
+        )
+        try:
+            configuration: Any = (
+                json.loads(raw_configuration)
+                if isinstance(raw_configuration, str)
+                else raw_configuration
+            )
+        except ValueError:
+            configuration = None
+        if not isinstance(configuration, dict):
+            raise SemanticViewInvalidError(
+                _("The view configuration must be a JSON object.")
+            )
+        try:
+            view: SemanticViewABC | None = layer.implementation.get_semantic_view(
+                name, configuration
+            )
+        except Exception as ex:  # pylint: disable=broad-except
+            logger.warning(
+                "Semantic view lookup failed for layer %s, view %s: %s",
+                layer_uuid,
+                name,
+                type(ex).__name__,
+            )
+            view = None
+        if view is None:

Review 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?



##########
superset/commands/semantic_layer/create.py:
##########
@@ -108,7 +111,36 @@ def validate(self) -> None:
             raise SemanticViewForbiddenError()
 
         name: str = self._properties.get("name", "")
-        configuration: dict[str, Any] = self._properties.get("configuration") or {}
+        raw_configuration: dict[str, Any] | str = (
+            self._properties.get("configuration") or {}
+        )
+        try:
+            configuration: Any = (
+                json.loads(raw_configuration)
+                if isinstance(raw_configuration, str)
+                else raw_configuration
+            )
+        except ValueError:
+            configuration = None
+        if not isinstance(configuration, dict):
+            raise SemanticViewInvalidError(
+                _("The view configuration must be a JSON object.")
+            )
+        try:
+            view: SemanticViewABC | None = layer.implementation.get_semantic_view(
+                name, configuration
+            )
+        except Exception as ex:  # pylint: disable=broad-except
+            logger.warning("Semantic view lookup failed: %s", type(ex).__name__)

Review 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.
   



##########
superset/commands/semantic_layer/create.py:
##########
@@ -108,7 +111,36 @@ def validate(self) -> None:
             raise SemanticViewForbiddenError()
 
         name: str = self._properties.get("name", "")
-        configuration: dict[str, Any] = self._properties.get("configuration") or {}
+        raw_configuration: dict[str, Any] | str = (
+            self._properties.get("configuration") or {}
+        )
+        try:
+            configuration: Any = (
+                json.loads(raw_configuration)
+                if isinstance(raw_configuration, str)
+                else raw_configuration
+            )
+        except ValueError:
+            configuration = None
+        if not isinstance(configuration, dict):
+            raise SemanticViewInvalidError(
+                _("The view configuration must be a JSON object.")
+            )
+        try:
+            view: SemanticViewABC | None = layer.implementation.get_semantic_view(

Review 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.
   



##########
docs/docs/using-superset/semantic-layer-connections.mdx:
##########
@@ -61,3 +61,9 @@ keeps dependent choices unavailable until that source is filled. Clearing an
 optional dependency can load choices for the empty state instead. Semantic
 views listed for an earlier dependency are discarded, and views cannot be added
 while dependent choices are loading.
+
+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

Review 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.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(semantic-layer): validate views before creation [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #45287:
URL: https://github.com/apache/superset/pull/45287#discussion_r4286776986


##########
docs/docs/using-superset/semantic-layer-connections.mdx:
##########
@@ -61,3 +61,9 @@ keeps dependent choices unavailable until that source is filled. Clearing an
 optional dependency can load choices for the empty state instead. Semantic
 views listed for an earlier dependency are discarded, and views cannot be added
 while dependent choices are loading.
+
+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
+unreachable, and does not add it. Other valid views in the same request can still

Review 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.
   
   ```suggestion
   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
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(semantic-layer): validate views before creation [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #45287:
URL: https://github.com/apache/superset/pull/45287#issuecomment-6174678323

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/45287?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `10.00000%` with `9 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 64.89%. Comparing base ([`0ce9b6c`](https://app.codecov.io/gh/apache/superset/commit/0ce9b6ca46c31a6150f3941ec90a9c938cc4d11b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`ba248a1`](https://app.codecov.io/gh/apache/superset/commit/ba248a1f90cddd7d425a844c9636715d747bb279?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/45287?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [superset/commands/semantic\_layer/create.py](https://app.codecov.io/gh/apache/superset/pull/45287?src=pr&el=tree&filepath=superset%2Fcommands%2Fsemantic_layer%2Fcreate.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY29tbWFuZHMvc2VtYW50aWNfbGF5ZXIvY3JlYXRlLnB5) | 11.11% | [8 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/45287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/semantic\_layers/api.py](https://app.codecov.io/gh/apache/superset/pull/45287?src=pr&el=tree&filepath=superset%2Fsemantic_layers%2Fapi.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvc2VtYW50aWNfbGF5ZXJzL2FwaS5weQ==) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/45287?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   > :exclamation:  There is a different number of reports uploaded between BASE (0ce9b6c) and HEAD (ba248a1). Click for more details.
   > 
   > <details><summary>HEAD has 4 uploads less than BASE</summary>
   >
   >| Flag | BASE (0ce9b6c) | HEAD (ba248a1) |
   >|------|------|------|
   >|python|7|3|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff             @@
   ##           master   #45287       +/-   ##
   ===========================================
   - Coverage   83.30%   64.89%   -18.41%     
   ===========================================
     Files        3039     3039               
     Lines      198382   198390        +8     
     Branches    46213    46214        +1     
   ===========================================
   - Hits       165260   128747    -36513     
   - Misses      29898    66730    +36832     
   + Partials     3224     2913      -311     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/45287/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/45287/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `34.98% <10.00%> (-0.01%)` | :arrow_down: |
   | [mysql](https://app.codecov.io/gh/apache/superset/pull/45287/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.99% <10.00%> (-0.01%)` | :arrow_down: |
   | [postgres](https://app.codecov.io/gh/apache/superset/pull/45287/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/45287/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `36.74% <10.00%> (-0.01%)` | :arrow_down: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/45287/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `53.07% <10.00%> (-33.86%)` | :arrow_down: |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/45287/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/45287/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/45287?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(semantic-layer): validate views before creation [superset]

Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #45287:
URL: https://github.com/apache/superset/pull/45287#issuecomment-6174321261

   ### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
   
   
   |  Name | Link |
   |:-:|------------------------|
   |<span aria-hidden="true">🔨</span> Latest commit | ba248a1f90cddd7d425a844c9636715d747bb279 |
   |<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6acfbb96dc7d30f39ac7948c |
   |<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-45287--superset-docs-preview.netlify.app](https://deploy-preview-45287--superset-docs-preview.netlify.app) |
   |<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />![QR Code](https://app.netlify.com/qr-code/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2RlcGxveS1wcmV2aWV3LTQ1Mjg3LS1zdXBlcnNldC1kb2NzLXByZXZpZXcubmV0bGlmeS5hcHAifQ.LTUqQN1TF-4R9Uk0Fr4lZNF5ZeeTYo5cz6bnT-qCvL8)<br /><br />_Use your smartphone camera to open QR code link._</details> |
   |<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DcpLCoAgEADQu8w6oSw0u0HHGGeUgj5iYkR092b3Fu-FlM89FZgAGvAZD1rEF6lOG6u1qmu4FeWAJaiK28oCmRzSdj4zyzVI0XtnmCz3bewdknXDSPD9) |
   ---
   <!-- [superset-docs-preview Preview](https://deploy-preview-45287--superset-docs-preview.netlify.app) -->
   _To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(semantic-layer): validate views before creation [superset]

Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi merged PR #45287:
URL: https://github.com/apache/superset/pull/45287


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(semantic-layer): validate views before creation [superset]

Posted by "gabotorresruiz (via GitHub)" <gi...@apache.org>.
gabotorresruiz commented on code in PR #45287:
URL: https://github.com/apache/superset/pull/45287#discussion_r4287082147


##########
superset/commands/semantic_layer/create.py:
##########
@@ -108,7 +111,36 @@ def validate(self) -> None:
             raise SemanticViewForbiddenError()
 
         name: str = self._properties.get("name", "")
-        configuration: dict[str, Any] = self._properties.get("configuration") or {}
+        raw_configuration: dict[str, Any] | str = (
+            self._properties.get("configuration") or {}
+        )
+        try:
+            configuration: Any = (
+                json.loads(raw_configuration)
+                if isinstance(raw_configuration, str)
+                else raw_configuration
+            )
+        except ValueError:
+            configuration = None
+        if not isinstance(configuration, dict):
+            raise SemanticViewInvalidError(
+                _("The view configuration must be a JSON object.")
+            )
+        try:
+            view: SemanticViewABC | None = layer.implementation.get_semantic_view(

Review 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.



##########
docs/docs/using-superset/semantic-layer-connections.mdx:
##########
@@ -61,3 +61,9 @@ keeps dependent choices unavailable until that source is filled. Clearing an
 optional dependency can load choices for the empty state instead. Semantic
 views listed for an earlier dependency are discarded, and views cannot be added
 while dependent choices are loading.
+
+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

Review 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?



##########
superset/commands/semantic_layer/create.py:
##########
@@ -108,7 +111,36 @@ def validate(self) -> None:
             raise SemanticViewForbiddenError()
 
         name: str = self._properties.get("name", "")
-        configuration: dict[str, Any] = self._properties.get("configuration") or {}
+        raw_configuration: dict[str, Any] | str = (
+            self._properties.get("configuration") or {}
+        )
+        try:
+            configuration: Any = (
+                json.loads(raw_configuration)
+                if isinstance(raw_configuration, str)
+                else raw_configuration
+            )
+        except ValueError:
+            configuration = None
+        if not isinstance(configuration, dict):
+            raise SemanticViewInvalidError(
+                _("The view configuration must be a JSON object.")
+            )
+        try:
+            view: SemanticViewABC | None = layer.implementation.get_semantic_view(
+                name, configuration
+            )
+        except Exception as ex:  # pylint: disable=broad-except
+            logger.warning("Semantic view lookup failed: %s", type(ex).__name__)

Review 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.
   
   ```suggestion
               logger.warning(
                   "Semantic view lookup failed for layer %s, view %s: %s",
                   layer_uuid,
                   name,
                   type(ex).__name__,
               )
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(semantic-layer): validate views before creation [superset]

Posted by "mikebridge (via GitHub)" <gi...@apache.org>.
mikebridge commented on PR #45287:
URL: https://github.com/apache/superset/pull/45287#issuecomment-6199149255

   Re CodeAnt's risk note on `json.loads`: addressed in b4f6d7048e. A serialized configuration that is not a JSON object (malformed, an array or a scalar) now raises `SemanticViewInvalidError` ("The view configuration must be a JSON object."), before the provider lookup. The batch endpoint reports that per view and carries on with the rest.
   
   Before this change it didn't abort the request: the `JSONDecodeError` became a generic per-view create failure through the `@transaction` handler. It also can't arise from the batch API, whose schema loads `configuration` as a dict. It can still arise from a direct command caller, so the error is now the right one. New test: `test_create_semantic_view_malformed_configuration`, red first.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org