eschutho commented on code in PR #24839:
URL: https://github.com/apache/superset/pull/24839#discussion_r1303511598


##########
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())

Review Comment:
   @hughhhh let's make this a different 422 error, not the same one that we're 
using for the 500. 



##########
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:
   same here, 422



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to