betodealmeida commented on a change in pull request #13893:
URL: https://github.com/apache/superset/pull/13893#discussion_r605146436
##########
File path: superset/queries/saved_queries/api.py
##########
@@ -252,3 +265,135 @@ def export(self, **kwargs: Any) -> Response:
as_attachment=True,
attachment_filename=filename,
)
+ @expose("/import/", methods=["POST"])
+ @protect()
+ @safe
+ @statsd_metrics
+ @event_logger.log_this_with_context(
+ action=lambda self, *args, **kwargs:
f"{self.__class__.__name__}.import_",
+ log_to_statsd=False,
+ )
+ def import_(self) -> Response:
+ """Import chart(s) with associated datasets and databases
+ ---
+ post:
+ requestBody:
+ required: true
+ content:
+ multipart/form-data:
+ schema:
+ type: object
+ properties:
+ formData:
+ description: upload file (ZIP)
+ type: string
+ format: binary
+ passwords:
+ description: JSON map of passwords for each file
+ type: string
+ overwrite:
+ description: overwrite existing databases?
+ type: bool
+ responses:
+ 200:
+ description: Chart import result
+ content:
+ application/json:
+ schema:
+ type: object
+ properties:
+ message:
+ type: string
+ 400:
+ $ref: '#/components/responses/400'
+ 401:
+ $ref: '#/components/responses/401'
+ 422:
+ $ref: '#/components/responses/422'
+ 500:
+ $ref: '#/components/responses/500'
+ """
+ upload = request.files.get("formData")
+ if not upload:
+ return self.response_400()
+ with ZipFile(upload) as bundle:
+ contents = get_contents_from_bundle(bundle)
+
+ passwords = (
+ json.loads(request.form["passwords"])
+ if "passwords" in request.form
+ else None
+ )
+ overwrite = request.form.get("overwrite") == "true"
+
+ command = ImportSavedQueriesCommand(
+ contents, passwords=passwords, overwrite=overwrite
+ )
+ try:
+ command.run()
+ return self.response(200, message="OK")
+ except CommandInvalidError as exc:
+ logger.warning("Import Saved Query failed")
+ return self.response_422(message=exc.normalized_messages())
+ except Exception as exc: # pylint: disable=broad-except
+ logger.exception("Import Saved Query failed")
+ return self.response_500(message=str(exc))
+ @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:
Review comment:
We don't need this for this PR.
Creating a new saved query would be an API for when the user clicks "save
query" in SQL Lab. Currently that flow uses the old API
(`savedqueryviewapi/api/create`), but when we eventually migrate it to the new
v1 API this is the endpoint that would be used.
I would suggest moving this out of the PR, and have a separate PR
introducing this and the command, so we can move "save query" to this endpoint.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]