mchades commented on code in PR #13571:
URL: https://github.com/apache/gravitino/pull/13571#discussion_r4216236673
##########
clients/client-python/gravitino/api/semantic/ai_context_object.py:
##########
@@ -146,57 +142,44 @@ def _normalize_json_value(
return value
if isinstance(value, dict):
- return _normalize_json_dict(value, path, visiting, container_depth + 1)
+ return _normalize_json_dict(value, path, visiting)
if isinstance(value, (list, tuple)):
- return _normalize_json_list(value, path, visiting, container_depth + 1)
+ return _normalize_json_list(value, path, visiting)
raise IllegalArgumentException(
f"Additional property {path} has non-JSON-compatible value type: "
f"{type(value).__name__}"
)
-def _normalize_json_dict(
- value: dict, path: str, visiting: set[int], container_depth: int
-) -> dict[str, Any]:
- _enter_container(value, path, visiting, container_depth)
+def _normalize_json_dict(value: dict, path: str, visiting: set[int]) ->
dict[str, Any]:
+ _enter_container(value, path, visiting)
try:
normalized = {}
for key, item in value.items():
Precondition.check_argument(
isinstance(key, str),
f"Additional property {path} contains a map key that is not a
string",
)
- normalized[key] = _normalize_json_value(
- item, f"{path}.{key}", visiting, container_depth
- )
+ normalized[key] = _normalize_json_value(item, f"{path}.{key}",
visiting)
return normalized
finally:
visiting.discard(id(value))
-def _normalize_json_list(
- value, path: str, visiting: set[int], container_depth: int
-) -> list[Any]:
- _enter_container(value, path, visiting, container_depth)
+def _normalize_json_list(value, path: str, visiting: set[int]) -> list[Any]:
+ _enter_container(value, path, visiting)
try:
return [
- _normalize_json_value(item, f"{path}[{index}]", visiting,
container_depth)
+ _normalize_json_value(item, f"{path}[{index}]", visiting)
for index, item in enumerate(value)
]
finally:
visiting.discard(id(value))
-def _enter_container(
- value: Any, path: str, visiting: set[int], container_depth: int
-) -> None:
- Precondition.check_argument(
- container_depth <= MAX_ADDITIONAL_PROPERTY_NESTING_DEPTH,
- f"Additional property {path} exceeds maximum nesting depth of "
- f"{MAX_ADDITIONAL_PROPERTY_NESTING_DEPTH}",
- )
+def _enter_container(value: Any, path: str, visiting: set[int]) -> None:
Review Comment:
Same rationale as on the Java side: AIContext is expected to contain shallow
metadata. Very deep programmatic input can raise `RecursionError`, but I'd
prefer to leave the current implementation unchanged in this PR and revisit
this when there is a concrete use case.
--
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]