eschutho commented on code in PR #24839: URL: https://github.com/apache/superset/pull/24839#discussion_r1304570617
########## superset/tags/commands/create.py: ########## @@ -60,3 +62,45 @@ def validate(self) -> None: ) if exceptions: raise TagInvalidError(exceptions=exceptions) + + +class CreateCustomTagWithRelationshipsCommand(CreateMixin, BaseCommand): + def __init__(self, data: dict[str, Any]): + self._tag = data["name"] + self._objects_to_tag = data.get("objects_to_tag") + self._description = data.get("description") + + def run(self) -> None: + self.validate() + try: + tag = TagDAO.get_by_name(self._tag.strip(), TagTypes.custom) + if self._objects_to_tag: + TagDAO.create_tag_relationship( + objects_to_tag=self._objects_to_tag, tag=tag + ) + + if self._description: + tag.description = self._description + db.session.commit() + + except DAOCreateFailedError as ex: + logger.exception(ex.exception) + raise TagCreateFailedError() from ex + + def validate(self) -> None: + exceptions = [] + # Validate object_id + if self._objects_to_tag: + if any(obj_id == 0 for obj_type, obj_id in self._objects_to_tag): + exceptions.append(TagCreateFailedError()) + + # Validate object type + for obj_type, obj_id in self._objects_to_tag: + object_type = to_object_type(obj_type) + if not object_type: + exceptions.append( + TagCreateFailedError(f"invalid object type {object_type}") Review Comment: ```suggestion TagInvalidError(f"invalid object type {object_type}") ``` -- 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: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org