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


##########
superset/mcp_service/chart/chart_helpers.py:
##########
@@ -1065,6 +1065,24 @@ def _resolve_filter_operator_and_value(
     return None, None
 
 
+def _safe_json_loads_dict(
+    raw: str | None, field_name: str, dashboard_id: int
+) -> dict[str, Any] | None:
+    """Parse a JSON string expected to be an object, returning *None* on 
failure."""
+    from superset.utils import json
+
+    try:
+        value = json.loads(raw or "{}")
+    except (TypeError, ValueError):
+        logger.warning(
+            "Failed to parse %s for dashboard %s, skipping native filter 
resolution.",
+            field_name,
+            dashboard_id,
+        )
+        return None
+    return value if isinstance(value, dict) else None

Review Comment:
   Only decode errors log, so well-formed non-dict JSON (`[1]`, `"s"`) is 
dropped silently. For `position_json` the message is also wrong: resolution 
continues with `{}` and returns a partial list (verified: a `TAB-1`-scoped 
filter is dropped). Logging every failure neutrally:
   
   ```suggestion
       try:
           value = json.loads(raw or "{}")
       except (TypeError, ValueError):
           value = None
       if isinstance(value, dict):
           return value
       logger.warning("Ignoring malformed %s for dashboard %s.", field_name, 
dashboard_id)
       return None
   ```



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