Copilot commented on code in PR #12117: URL: https://github.com/apache/gravitino/pull/12117#discussion_r3621138736
########## clients/client-python/gravitino/dto/requests/view_create_request.py: ########## @@ -0,0 +1,95 @@ +# 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 dataclasses import dataclass, field +from typing import Optional + +from dataclasses_json import config + +from gravitino.dto.rel.column_dto import ColumnDTO +from gravitino.dto.rel.json_serdes.representation_serdes import RepresentationSerdes +from gravitino.dto.rel.representation_dto import RepresentationDTO +from gravitino.dto.rel.sql_representation_dto import SQLRepresentationDTO +from gravitino.rest.rest_message import RESTRequest +from gravitino.utils.precondition import Precondition + + +@dataclass +class ViewCreateRequest(RESTRequest): + """Represents a request to create a view.""" + + _name: str = field(metadata=config(field_name="name")) + _columns: Optional[list[ColumnDTO]] = field( + default=None, metadata=config(field_name="columns") + ) + _representations: Optional[list[RepresentationDTO]] = field( + default=None, + metadata=config( + field_name="representations", + encoder=lambda items: [ + RepresentationSerdes.serialize(item) for item in items + ], + decoder=lambda values: [ + RepresentationSerdes.deserialize(value) for value in values + ], + ), + ) Review Comment: `_representations` is declared optional, but the dataclasses_json `encoder` assumes it is iterable. If a caller creates `ViewCreateRequest(_name=...)` and calls `to_json()` before `validate()`, this will raise a `TypeError` (unlike other request DTOs which exclude `None` before invoking list encoders). Consider excluding the field when it is `None`, and make the encoder/decoder tolerate `None` values for consistency with `TableCreateRequest`'s optional list fields. -- 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]
