eschutho commented on code in PR #24839: URL: https://github.com/apache/superset/pull/24839#discussion_r1302011450
########## superset/tags/api.py: ########## @@ -131,6 +141,131 @@ def __repr__(self) -> str: f'{self.appbuilder.app.config["VERSION_SHA"]}' ) + @expose("/", methods=("POST",)) + @protect() + @safe + @statsd_metrics + @event_logger.log_this_with_context( + action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.post", + log_to_statsd=False, + ) + def post(self) -> Response: + """Creates a new Tags and tag items + --- + post: + description: >- + Create a new Tag + requestBody: + description: Tag schema + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/{{self.__class__.__name__}}.post' + responses: + 201: + description: Tag added + content: + application/json: + schema: + type: object + properties: + id: + type: number + result: + $ref: '#/components/schemas/{{self.__class__.__name__}}.post' + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 422: + $ref: '#/components/responses/422' + 500: + $ref: '#/components/responses/500' + """ + try: + item = self.add_model_schema.load(request.json) + except ValidationError as error: + return self.response_400(message=error.messages) + try: + CreateCustomTagWithRelationshipsCommand(item).run() + return self.response(201) + except TagInvalidError as ex: + return self.response_422(message=ex.normalized_messages()) + except TaggedObjectDeleteFailedError as ex: Review Comment: I see. It looks like we're returning TagCreateFailedError from the Command after validation and after the DaoCreateFailedError. IMO, TagInvalidError would be a 422, and TagCreateFailedError a 500, and then we can return the TagCreateFailedError after all the validation has been completed, only returning the TagInvalidError for user-generated validation errors where a retry is in order. Then return the TagCreateFailedError for system errors. -- 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