zephyring commented on code in PR #24964:
URL: https://github.com/apache/superset/pull/24964#discussion_r1321918629
##########
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:
oh I just made up those Exception names to describe the failure scenarios
--
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]