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


##########
clients/client-python/gravitino/dto/requests/policy_create_request.py:
##########
@@ -0,0 +1,79 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from dataclasses import dataclass, field
+
+from dataclasses_json import config, dataclass_json
+
+from gravitino.dto.policy_dto import PolicyContentDTO
+from gravitino.rest.rest_message import RESTRequest
+from gravitino.utils.precondition import Precondition
+
+
+@dataclass_json
+@dataclass
+class PolicyCreateRequest(RESTRequest):
+    """Represents a request to create a policy."""
+
+    _name: str = field(metadata=config(field_name="name"))
+    _policy_type: str = field(metadata=config(field_name="policyType"))
+    _comment: str | None = field(default=None, 
metadata=config(field_name="comment"))
+    _enabled: bool = field(default=True, metadata=config(field_name="enabled"))
+    _content: PolicyContentDTO | None = field(
+        default=None,
+        metadata=config(
+            field_name="content",
+            encoder=lambda content: content.to_dict() if content is not None 
else None,
+        ),

Review Comment:
   [P2] Decode policy content when reading request JSON
   
   Only an encoder is registered for the polymorphic content, so 
`PolicyCreateRequest.from_json(request.to_json())` leaves `content` as a plain 
`dict`; calling `validate()` then raises `AttributeError: 'dict' object has no 
attribute 'validate'`, and serializing it again also fails. 
`UpdatePolicyContentRequest` has the same problem for `newContent`, including 
`policy_change()`. This reproduces with valid custom content and all seven 
built-in types. Please dispatch deserialization through 
`PolicyContentDTO.from_dict_by_type` using the sibling `policyType`, as 
`PolicyDTO.from_dict` already does, and cover request round trips.



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