aminghadersohi commented on code in PR #40957:
URL: https://github.com/apache/superset/pull/40957#discussion_r3493546979


##########
superset/mcp_service/dashboard/tool/update_dashboard.py:
##########
@@ -113,22 +113,58 @@ def _merge_json_metadata(dashboard: Any, overrides: 
dict[str, Any]) -> str:
     existing: dict[str, Any] = {}
     if dashboard.json_metadata:
         try:
-            parsed = json.loads(dashboard.json_metadata)
-            if isinstance(parsed, dict):
+            if isinstance(parsed := json.loads(dashboard.json_metadata), dict):
                 existing = parsed
         except (ValueError, TypeError):
             pass
     existing.update(overrides)
     return json.dumps(existing)
 
 
+# Typed json_metadata convenience fields. Each maps 1:1 to a json_metadata
+# key but is exposed as a validated field so an LLM does not have to hand-build
+# the raw ``json_metadata_overrides`` dict for common toggles.
+_TYPED_METADATA_FIELDS = (
+    "cross_filters_enabled",
+    "refresh_frequency",
+    "filter_bar_orientation",
+)
+
+
+def _collect_metadata_overrides(request: UpdateDashboardRequest) -> dict[str, 
Any]:
+    """Combine the generic ``json_metadata_overrides`` with the typed fields.
+
+    A key set via both a typed field and the generic dict is ambiguous, so a
+    collision raises ``ValueError``. Otherwise the typed fields are layered on
+    top of the generic overrides. The generic dict stays as an escape hatch for
+    keys without a typed field.
+    """
+    overrides: dict[str, Any] = dict(request.json_metadata_overrides or {})
+    typed = {
+        field: value
+        for field in _TYPED_METADATA_FIELDS
+        if (value := getattr(request, field)) is not None
+    }

Review Comment:
   Declining as a nit — covered by the response on the `_TYPED_METADATA_FIELDS` 
thread.



##########
superset/mcp_service/dashboard/tool/update_dashboard.py:
##########
@@ -152,57 +188,117 @@ def _apply_field_updates(dashboard: Any, request: 
UpdateDashboardRequest) -> lis
         dashboard.position_json = json.dumps(request.position_json)
         changed.append("position_json")
 
-    if request.json_metadata_overrides is not None:
-        dashboard.json_metadata = _merge_json_metadata(
-            dashboard, request.json_metadata_overrides
-        )
+    metadata_overrides = _collect_metadata_overrides(request)

Review Comment:
   Declining as a nit — covered by the response on the `_TYPED_METADATA_FIELDS` 
thread.



##########
superset/mcp_service/dashboard/tool/update_dashboard.py:
##########
@@ -212,6 +308,10 @@ def update_dashboard(
     if auth_error is not None:
         return auth_error
 
+    validation_error = _validate_update_request(dashboard, request)

Review Comment:
   Declining as a nit — covered by the response on the `_TYPED_METADATA_FIELDS` 
thread.



##########
superset/mcp_service/dashboard/tool/update_dashboard.py:
##########
@@ -212,6 +314,10 @@ def update_dashboard(
     if auth_error is not None:
         return auth_error
 
+    validation_error = _validate_update_request(dashboard, request)

Review Comment:
   Declining as a nit — covered by the response on the `_TYPED_METADATA_FIELDS` 
thread.



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