You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "zhaoyongjie (via GitHub)" <gi...@apache.org> on 2023/08/23 12:32:44 UTC
[GitHub] [superset] zhaoyongjie commented on a diff in pull request #24839: feat: Update Tags CRUD API
zhaoyongjie commented on code in PR #24839:
URL: https://github.com/apache/superset/pull/24839#discussion_r1302946326
##########
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 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))
Review Comment:
Hey @hughhhh 500 error means that the server encountered an [unexpected condition](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500), you've got `TagCreateFailedError` why you raise 500 error still?
--
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-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org