mchades commented on code in PR #14208:
URL: https://github.com/apache/gravitino/pull/14208#discussion_r4408001039


##########
mcp-server/mcp_server/client/plain/utils.py:
##########
@@ -37,6 +39,29 @@ def extract_content_from_response(response, field: str, 
default="") -> str:
     return json.dumps(response_json.get(field, default))
 
 
+def extract_list_from_response(response, field: str) -> str:
+    """Extract a required JSON array without rounding fractional numbers.
+
+    Propagate server errors and reject malformed envelopes instead of returning
+    an empty result for a failed discovery request.
+    """
+    try:
+        payload = simplejson.loads(response.content, use_decimal=True)
+    except simplejson.JSONDecodeError:
+        response.raise_for_status()
+        raise
+    if isinstance(payload, dict):
+        _handle_gravitino_exception(payload)
+    response.raise_for_status()
+    if not isinstance(payload, dict) or "code" not in payload:
+        raise GravitinoException("Invalid Gravitino response: missing code")
+    if not isinstance(payload.get(field), list):
+        raise GravitinoException(
+            f"Invalid Gravitino response: {field} must be a JSON array"
+        )
+    return simplejson.dumps(payload[field], use_decimal=True)

Review Comment:
   Fixed in b71162e70f. Invalid JSON in successful responses now raises 
`GravitinoException` with `Invalid Gravitino response: invalid JSON`, 
preserving the original cause. Non-2xx responses still go through 
`raise_for_status()`. Tests cover both cases.



##########
mcp-server/pyproject.toml:
##########
@@ -31,6 +31,8 @@ dependencies = [
     "pydantic>=2.12.0,<3",
     # httpx.Auth plugin for hop-2 client_credentials fetch/cache.
     "httpx-auth>=0.22,<0.24",
+    # Preserve exact JSON numbers in Semantic Model metric discovery responses.
+    "simplejson==3.20.1",

Review Comment:
   Keeping `simplejson==3.20.1` to match the Python client's decimal 
serialization dependency and keep its version consistent across the 
lockfile-based and Gradle installation paths. Updates can be made explicitly 
with the numeric-precision regression tests.



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

Reply via email to