From 26d34727d3ceb30a59727819254d45f1c504765e Mon Sep 17 00:00:00 2001 From: Ville Brofeldt <33317356+villebro@users.noreply.github.com> Date: Mon, 29 Jun 2020 09:54:01 +0300 Subject: [PATCH] fix: make time grain nullable in chart data endpoint (#10187) * fix: make time grain nullable * add test * lint --- superset/charts/schemas.py | 2 ++ tests/charts/schema_tests.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/superset/charts/schemas.py b/superset/charts/schemas.py index 06dc111faf..3cd246844a 100644 --- a/superset/charts/schemas.py +++ b/superset/charts/schemas.py @@ -596,10 +596,12 @@ class ChartDataExtrasSchema(Schema): ), ), example="P1D", + allow_none=True, ) druid_time_origin = fields.String( description="Starting point for time grain counting on legacy Druid " "datasources. Used to change e.g. Monday/Sunday first-day-of-week.", + allow_none=True, ) diff --git a/tests/charts/schema_tests.py b/tests/charts/schema_tests.py index 5f0ef16760..fc51d02a83 100644 --- a/tests/charts/schema_tests.py +++ b/tests/charts/schema_tests.py @@ -14,14 +14,15 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +# isort:skip_file """Unit tests for Superset""" from typing import Any, Dict, Tuple +from tests.test_app import app from superset.charts.schemas import ChartDataQueryContextSchema from superset.common.query_context import QueryContext from tests.base_tests import SupersetTestCase from tests.fixtures.query_context import get_query_context -from tests.test_app import app def load_query_context(payload: Dict[str, Any]) -> Tuple[QueryContext, Dict[str, Any]]: @@ -59,3 +60,13 @@ class SchemaTestCase(SupersetTestCase): query_context, errors = ChartDataQueryContextSchema().load(payload) self.assertIn("row_limit", errors["queries"][0]) self.assertIn("row_offset", errors["queries"][0]) + + def test_query_context_null_timegrain(self): + self.login(username="admin") + table_name = "birth_names" + table = self.get_table_by_name(table_name) + payload = get_query_context(table.name, table.id, table.type) + + payload["queries"][0]["extras"]["time_grain_sqla"] = None + _, errors = ChartDataQueryContextSchema().load(payload) + self.assertEqual(errors, {})