From 3ec863066fa3f48c0751b1ff36bb4a636e56c836 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Wed, 30 Jun 2021 12:34:54 +0100 Subject: [PATCH] fix: raise unexpected error when orderby is empty (#15353) * fix: raise unexpected error when orderby is empty * fix ut --- superset/charts/schemas.py | 14 ++++++++++++-- tests/fixtures/query_context.py | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/superset/charts/schemas.py b/superset/charts/schemas.py index ef11d8412e2b9..7c8f1e0d8fbf1 100644 --- a/superset/charts/schemas.py +++ b/superset/charts/schemas.py @@ -1007,11 +1007,21 @@ class Meta: # pylint: disable=too-few-public-methods allow_none=True, ) orderby = fields.List( - fields.List(fields.Raw()), + fields.Tuple( + ( + fields.Raw( + validate=[ + Length(min=1, error=_("orderby column must be populated")) + ], + allow_none=False, + ), + fields.Boolean(), + ) + ), description="Expects a list of lists where the first element is the column " "name which to sort by, and the second element is a boolean.", allow_none=True, - example=[["my_col_1", False], ["my_col_2", True]], + example=[("my_col_1", False), ("my_col_2", True)], ) where = fields.String( description="WHERE clause to be added to queries using AND operator." diff --git a/tests/fixtures/query_context.py b/tests/fixtures/query_context.py index 12fddc630d49a..d0486a42ee4fc 100644 --- a/tests/fixtures/query_context.py +++ b/tests/fixtures/query_context.py @@ -31,7 +31,7 @@ }, "groupby": ["name"], "metrics": [{"label": "sum__num"}], - "orderby": [["sum__num", False]], + "orderby": [("sum__num", False)], "row_limit": 100, "granularity": "ds", "time_range": "100 years ago : now",