villebro commented on a change in pull request #9964:
URL:
https://github.com/apache/incubator-superset/pull/9964#discussion_r449918739
##########
File path: superset/charts/schemas.py
##########
@@ -664,6 +663,10 @@ class ChartDataQueryObjectSchema(Schema):
timeseries_limit = fields.Integer(
description="Maximum row count for timeseries queries. Default: `0`",
)
+ timeseries_limit_metric = fields.Integer(
+ description="Maximum row count for timeseries queries. Default: `0`",
Review comment:
Good catch 👍 The description should probably be updated to read `Metric
used to limit timeseries queries by`.
##########
File path: superset/dashboards/api.py
##########
@@ -196,13 +198,14 @@ def post(self) -> Response:
"""
if not request.is_json:
return self.response_400(message="Request is not JSON")
- item = self.add_model_schema.load(request.json)
+ try:
+ item = self.add_model_schema.load(request.json)
# This validates custom Schema with custom validations
- if item.errors:
- return self.response_400(message=item.errors)
+ except ValidationError as err:
+ return self.response_400(message=err.messages)
Review comment:
Being picky, but is it more pythonic to assign `error` as opposed to
`err`? (Applies to other places, too)
##########
File path: superset/charts/api.py
##########
@@ -446,13 +451,13 @@ def data(self) -> Response:
else:
return self.response_400(message="Request is not JSON")
try:
- query_context, errors =
ChartDataQueryContextSchema().load(json_body)
- if errors:
- return self.response_400(
- message=_("Request is incorrect: %(error)s", error=errors)
- )
+ query_context = ChartDataQueryContextSchema().load(json_body)
except KeyError:
return self.response_400(message="Request is incorrect")
+ except ValidationError as err:
+ return self.response_400(
+ _("Request is incorrect: %(error)s", error=err.messages)
+ )
Review comment:
Is `except KeyError` still needed here? Based on the docs, `load` only
raises `ValidationError` in 3.0+:
https://marshmallow.readthedocs.io/en/stable/_modules/marshmallow/schema.html#Schema.load
##########
File path: tests/charts/schema_tests.py
##########
@@ -39,27 +40,27 @@ def test_query_context_limit_and_offset(self):
# Use defaults
payload["queries"][0].pop("row_limit", None)
payload["queries"][0].pop("row_offset", None)
- query_context, errors = load_query_context(payload)
- self.assertEqual(errors, {})
+ query_context = load_query_context(payload)
query_object = query_context.queries[0]
self.assertEqual(query_object.row_limit, app.config["ROW_LIMIT"])
self.assertEqual(query_object.row_offset, 0)
# Valid limit and offset
payload["queries"][0]["row_limit"] = 100
payload["queries"][0]["row_offset"] = 200
- query_context, errors = ChartDataQueryContextSchema().load(payload)
- self.assertEqual(errors, {})
+ query_context = ChartDataQueryContextSchema().load(payload)
query_object = query_context.queries[0]
self.assertEqual(query_object.row_limit, 100)
self.assertEqual(query_object.row_offset, 200)
# too low limit and offset
payload["queries"][0]["row_limit"] = 0
payload["queries"][0]["row_offset"] = -1
- query_context, errors = ChartDataQueryContextSchema().load(payload)
- self.assertIn("row_limit", errors["queries"][0])
- self.assertIn("row_offset", errors["queries"][0])
+ try:
+ _ = ChartDataQueryContextSchema().load(payload)
+ except ValidationError as errors:
+ self.assertIn("row_limit", errors.messages["queries"][0])
+ self.assertIn("row_offset", errors.messages["queries"][0])
Review comment:
If this doesn't raise, won't the assertions just be skipped?
----------------------------------------------------------------
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]