codeant-ai-for-open-source[bot] commented on code in PR #37856:
URL: https://github.com/apache/superset/pull/37856#discussion_r2789577895


##########
superset-core/src/superset_core/extensions/types.py:
##########
@@ -56,19 +56,37 @@ class ModuleFederationConfig(BaseModel):
 
 
 class ContributionConfig(BaseModel):
-    """Configuration for frontend UI contributions."""
+    """Configuration for frontend UI contributions.
+
+    Views and menus use a nested structure: type -> scope -> location -> 
contributions.
+
+    Example:
+        {
+            "views": {
+                "sqllab": {
+                    "panels": [{"id": "my-ext.panel", "name": "My Panel"}],
+                    "leftSidebar": [{"id": "my-ext.sidebar", "name": 
"Sidebar"}]
+                }
+            },
+            "menus": {
+                "sqllab": {
+                    "editor": {"primary": [...], "secondary": [...]}
+                }
+            }
+        }
+    """
 
     commands: list[dict[str, Any]] = Field(
         default_factory=list,
         description="Command contributions",
     )
-    views: dict[str, list[dict[str, Any]]] = Field(
+    views: dict[str, dict[str, list[dict[str, Any]]]] = Field(

Review Comment:
   **Suggestion:** The `views` field type was tightened from a flat mapping to 
a doubly nested mapping, which will cause Pydantic validation failures for any 
existing extensions that still use the documented legacy `"sqllab.panels": 
[...]` dot-notation format; unlike `menus`, which still accepts the old shape, 
`views` can no longer deserialize those manifests. Relaxing the type to a 
simple dict preserves compatibility with both the old flat keys and the new 
nested shape while still allowing the frontend to interpret the structure 
correctly. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Legacy extensions with flat views fail schema validation.
   - ⚠️ Affected extensions cannot load frontend contributions.
   - ⚠️ Menus remain compatible while views break asymmetrically.
   ```
   </details>
   
   ```suggestion
       views: dict[str, Any] = Field(
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Create an extension configuration file `extension.json` with a legacy 
flat views shape
   as documented before this refactor, for example:
   
      ```json
   
      {
   
        "frontend": {
   
          "contributions": {
   
            "views": {
   
              "sqllab.panels": [
   
                { "id": "my-ext.panel", "name": "My Panel" }
   
              ]
   
            },
   
            "menus": {
   
              "sqllab.editor": {
   
                "primary": []
   
              }
   
            }
   
          }
   
        }
   
      }
   
      ```
   
   2. The Superset backend (or build tool) loads `extension.json` and validates 
it against
   `ExtensionConfig` in `superset-core/src/superset_core/extensions/types.py`, 
where
   `ExtensionConfigFrontend.contributions` is a `ContributionConfig` instance 
(see
   `ExtensionConfigFrontend` in this file).
   
   3. During Pydantic validation of `ContributionConfig` at `views` (lines 
83–86), Pydantic
   attempts to coerce the `views` object into `dict[str, dict[str, 
list[dict[str, Any]]]]`.
   The key `"sqllab.panels"` maps to a list, not to a nested dict, so the value 
type does not
   match the expected `dict[str, list[dict[str, Any]]]`.
   
   4. Pydantic raises a `ValidationError` for the `views` field while the 
`menus` field
   passes validation (its type `dict[str, dict[str, Any]]` is still compatible 
with the
   legacy `"sqllab.editor": {...}` shape), causing the extension configuration 
(and therefore
   that extension) to fail to load/validate using the current schema.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-core/src/superset_core/extensions/types.py
   **Line:** 83:83
   **Comment:**
        *Logic Error: The `views` field type was tightened from a flat mapping 
to a doubly nested mapping, which will cause Pydantic validation failures for 
any existing extensions that still use the documented legacy `"sqllab.panels": 
[...]` dot-notation format; unlike `menus`, which still accepts the old shape, 
`views` can no longer deserialize those manifests. Relaxing the type to a 
simple dict preserves compatibility with both the old flat keys and the new 
nested shape while still allowing the frontend to interpret the structure 
correctly.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37856&comment_hash=5a52f8da4ec28cf2b8972b18e473c2fb13b10024d1dd0a15ef74ab4d7d7d8b26&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37856&comment_hash=5a52f8da4ec28cf2b8972b18e473c2fb13b10024d1dd0a15ef74ab4d7d7d8b26&reaction=dislike'>👎</a>



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to