Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: address all disabled pylint checks in charts/api.py #10932

Merged
merged 5 commits into from
Sep 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions superset/charts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ def post(self) -> Response:
@protect()
@safe
@statsd_metrics
def put( # pylint: disable=too-many-return-statements, arguments-differ
self, pk: int
) -> Response:
def put(self, pk: int) -> Response:
"""Changes a Chart
---
put:
Expand Down Expand Up @@ -291,33 +289,37 @@ def put( # pylint: disable=too-many-return-statements, arguments-differ
500:
$ref: '#/components/responses/500'
"""

if not request.is_json:
return self.response_400(message="Request is not JSON")
try:
item = self.edit_model_schema.load(request.json)
# This validates custom Schema with custom validations
except ValidationError as error:
return self.response_400(message=error.messages)

try:
changed_model = UpdateChartCommand(g.user, pk, item).run()
return self.response(200, id=changed_model.id, result=item)
response = self.response(200, id=changed_model.id, result=item)
except ChartNotFoundError:
return self.response_404()
response = self.response_404()
except ChartForbiddenError:
return self.response_403()
response = self.response_403()
except ChartInvalidError as ex:
return self.response_422(message=ex.normalized_messages())
response = self.response_422(message=ex.normalized_messages())
except ChartUpdateFailedError as ex:
logger.error(
"Error updating model %s: %s", self.__class__.__name__, str(ex)
)
return self.response_422(message=str(ex))
response = self.response_422(message=str(ex))

return response

@expose("/<pk>", methods=["DELETE"])
@protect()
@safe
@statsd_metrics
def delete(self, pk: int) -> Response: # pylint: disable=arguments-differ
def delete(self, pk: int) -> Response:
"""Deletes a Chart
---
delete:
Expand Down Expand Up @@ -367,9 +369,7 @@ def delete(self, pk: int) -> Response: # pylint: disable=arguments-differ
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
def bulk_delete(
self, **kwargs: Any
) -> Response: # pylint: disable=arguments-differ
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk Charts
---
delete:
Expand Down Expand Up @@ -424,7 +424,7 @@ def bulk_delete(
@protect()
@safe
@statsd_metrics
def data(self) -> Response: # pylint: disable=too-many-return-statements
def data(self) -> Response:
"""
Takes a query context constructed in the client and returns payload
data response for the given query.
Expand Down Expand Up @@ -478,10 +478,15 @@ def data(self) -> Response: # pylint: disable=too-many-return-statements
if query.get("error"):
return self.response_400(message=f"Error: {query['error']}")
result_format = query_context.result_format

response = self.response_400(
message=f"Unsupported result_format: {result_format}"
)

if result_format == ChartDataResultFormat.CSV:
# return the first result
result = payload[0]["data"]
return CsvResponse(
response = CsvResponse(
result,
status=200,
headers=generate_download_headers("csv"),
Expand All @@ -494,9 +499,9 @@ def data(self) -> Response: # pylint: disable=too-many-return-statements
)
resp = make_response(response_data, 200)
resp.headers["Content-Type"] = "application/json; charset=utf-8"
return resp
response = resp

return self.response_400(message=f"Unsupported result_format: {result_format}")
return response

@expose("/<pk>/cache_screenshot/", methods=["GET"])
@protect()
Expand Down