sunyuhan1998 commented on code in PR #10760: URL: https://github.com/apache/gravitino/pull/10760#discussion_r3090428867
########## clients/client-python/gravitino/dto/requests/tags_associate_request.py: ########## @@ -0,0 +1,70 @@ +# 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 typing import List, Optional + +from dataclasses_json import config + +from gravitino.rest.rest_message import RESTRequest + + +@dataclass +class TagsAssociateRequest(RESTRequest): + """Represents a request to associate tags with a metadata object.""" + + _tags_to_add: Optional[List[str]] = field( + default=None, metadata=config(field_name="tagsToAdd") + ) + _tags_to_remove: Optional[List[str]] = field( + default=None, metadata=config(field_name="tagsToRemove") + ) + + def __init__( + self, + tags_to_add: Optional[List[str]] = None, + tags_to_remove: Optional[List[str]] = None, + ) -> None: + self._tags_to_add = tags_to_add + self._tags_to_remove = tags_to_remove + + def validate(self) -> None: + """Validates the request. + + Raises: + ValueError: If both tags_to_add and tags_to_remove are None. + """ + if self._tags_to_add is None and self._tags_to_remove is None: + raise ValueError( + "tags_to_add and tags_to_remove cannot both be null" + ) + + if self._tags_to_add is not None: + for tag in self._tags_to_add: + if not tag or not tag.strip(): + raise ValueError( + "tags_to_add must not contain null or empty tag names" + ) + + if self._tags_to_remove is not None: + for tag in self._tags_to_remove: + if not tag or not tag.strip(): + raise ValueError( + "tags_to_remove must not contain null or empty tag names" + ) Review Comment: Thanks, it's done. -- 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]
