eschutho commented on code in PR #24964: URL: https://github.com/apache/superset/pull/24964#discussion_r1321914888
########## superset/tags/api.py: ########## @@ -192,14 +195,77 @@ def post(self) -> Response: return self.response(201) except TagInvalidError as ex: return self.response_422(message=ex.normalized_messages()) - except TagCreateFailedError as ex: - logger.error( - "Error creating model %s: %s", - self.__class__.__name__, - str(ex), - exc_info=True, - ) - return self.response_500(message=str(ex)) + + @expose("/bulk_create", methods=("POST",)) + @protect() + @safe + @statsd_metrics + @event_logger.log_this_with_context( + action=lambda self, *args, **kwargs: f"{self.__class__.__name__}.bulk_create", + log_to_statsd=False, + ) + def bulk_create(self) -> Response: + """Bulk create tags and tagged objects + --- + post: + summary: Get all objects associated with a tag + parameters: + - in: path + schema: + type: integer + name: tag_id + requestBody: + description: Tag schema + required: true + content: + application/json: + schema: + type: object + properties: + tags: + description: list of tag names to add to object + type: array + items: + type: string + objects_to_tag: + description: list of object names to add to object + type: array + items: + type: array + responses: + 200: + description: Tag added to favorites + content: + application/json: + schema: + type: object + properties: + result: + type: object + 302: + description: Redirects to the current digest + 400: + $ref: '#/components/responses/400' + 401: + $ref: '#/components/responses/401' + 404: + $ref: '#/components/responses/404' + 500: + $ref: '#/components/responses/500' + """ + try: + item = TagPostBulkSchema().load(request.json) + except ValidationError as error: + return self.response_400(message=error.messages) + try: + for tag in item.get("tags"): + item = self.add_model_schema.load( + {"name": tag, "objects_to_tag": item.get("objects_to_tag")} + ) + CreateCustomTagWithRelationshipsCommand(item).run() + return self.response(201) + except TagInvalidError as ex: Review Comment: The ResourceNotFound and TagNotFound errors will raise a different status code (404), so they're caught separately. What's the DuplicateTagOnResource? I couldn't find a reference to that error in the code. -- 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