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


##########
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:
   Fixed in a1211ac13. Both requests only registered an encoder for the 
content, so dataclasses_json left it as a plain dict on the way in. 
PolicyCreateRequest and UpdatePolicyContentRequest now deserialize explicitly 
and dispatch the content through PolicyContentDTO.from_dict_by_type using the 
sibling policyType, the same way PolicyDTO.from_dict does it. Added JSON 
round-trip tests for both requests covering custom content and all seven 
built-in types — the decoded content is typed, validate() passes, and 
policy_change() works on the decoded update request. Full client-python suite: 
1,359 passed; pylint 10/10 on the changed files.



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