From 5dba2f4b56afe4bb8e27a96ee9ce475cf8f4ab47 Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Mon, 4 Nov 2019 12:00:41 -0800 Subject: [PATCH] [SIP-15] Adding grace period (#8490) --- docs/installation.rst | 26 +++++++++++++++++++++++++- superset/config.py | 7 ++++++- superset/views/utils.py | 11 +++++++++-- tests/utils_tests.py | 15 +++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/docs/installation.rst b/docs/installation.rst index f69b5e768..42750a77a 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -1356,9 +1356,33 @@ To remedy this rather than having to define the date/time format for every non-I } } -Additionally to aid with transparency the current endpoint behavior is explicitly called out in the chart time range (post SIP-15 this will be [start, end) for all connectors and databases). One can override the defaults on a per database level via the ``extra`` +**New deployments** + +All new Superset deployments should enable SIP-15 via, + +.. code-block:: python + + SIP_15_ENABLED = True + +**Existing deployments** + +Given that it is not apparent whether the chart creator was aware of the time range inconsistencies (and adjusted the endpoints accordingly) changing the behavior of all charts is overly aggressive. Instead SIP-15 proivides a soft transistion allowing producers (chart owners) to see the impact of the proposed change and adjust their charts accordingly. + +Prior to enabling SIP-15 existing deployments should communicate to their users the impact of the change and define a grace period end date (exclusive of course) after which all charts will conform to the [start, end) interval, i.e., + +.. code-block:: python + + from dateime import date + + SIP_15_ENABLED = True + SIP_15_GRACE_PERIOD_END = date(, ,
) + +To aid with transparency the current endpoint behavior is explicitly called out in the chart time range (post SIP-15 this will be [start, end) for all connectors and databases). One can override the defaults on a per database level via the ``extra`` parameter :: { "time_range_endpoints": ["inclusive", "inclusive"] } + + +Note in a future release the interim SIP-15 logic will be removed (including the ``time_grain_endpoints`` form-data field) via a code change and Alembic migration. diff --git a/superset/config.py b/superset/config.py index b0852892a..0023fed1c 100644 --- a/superset/config.py +++ b/superset/config.py @@ -28,7 +28,8 @@ import logging import os import sys from collections import OrderedDict -from typing import Any, Callable, Dict, List +from datetime import date +from typing import Any, Callable, Dict, List, Optional from celery.schedules import crontab from dateutil import tz @@ -698,7 +699,11 @@ SQLALCHEMY_EXAMPLES_URI = None # range endpoints adhere to [start, end). For existing deployments admins should provide # a dedicated period of time to allow chart producers to update their charts before # mass migrating all charts to use the [start, end) interval. +# +# Note if no end date for the grace period is specified then the grace period is +# indefinite. SIP_15_ENABLED = False +SIP_15_GRACE_PERIOD_END: Optional[date] = None # exclusive SIP_15_DEFAULT_TIME_RANGE_ENDPOINTS = ["unknown", "inclusive"] SIP_15_TOAST_MESSAGE = 'Action Required: Preview then save your chart using the new time range endpoints here.' diff --git a/superset/views/utils.py b/superset/views/utils.py index b98e8cd07..76255b9f0 100644 --- a/superset/views/utils.py +++ b/superset/views/utils.py @@ -16,6 +16,7 @@ # under the License. # pylint: disable=C,R,W from collections import defaultdict +from datetime import date from typing import Any, Dict, List, Optional, Tuple from urllib import parse @@ -212,14 +213,20 @@ def get_time_range_endpoints( Get the slice aware time range endpoints from the form-data falling back to the SQL database specific definition or default if not defined. - For SIP-15 all new slices use the [start, end) interval which is consistent with the - native Druid connector. + When SIP-15 is enabled all slices and will the [start, end) interval. If the grace + period is defined and has ended all slices will adhere to the [start, end) interval. :param form_data: The form-data :param slc: The chart :returns: The time range endpoints tuple """ + if ( + app.config["SIP_15_GRACE_PERIOD_END"] + and date.today() >= app.config["SIP_15_GRACE_PERIOD_END"] + ): + return (TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE) + endpoints = form_data.get("time_range_endpoints") if slc and not endpoints: diff --git a/tests/utils_tests.py b/tests/utils_tests.py index 8268f7fca..d767fe140 100644 --- a/tests/utils_tests.py +++ b/tests/utils_tests.py @@ -920,3 +920,18 @@ class UtilsTestCase(unittest.TestCase): ) self.assertIsNone(get_time_range_endpoints(form_data={}, slc=slc)) + + with app.app_context(): + app.config["SIP_15_GRACE_PERIOD_END"] = date.today() + timedelta(days=1) + + self.assertEqual( + get_time_range_endpoints(form_data={"datasource": "1__table"}, slc=slc), + (TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.INCLUSIVE), + ) + + app.config["SIP_15_GRACE_PERIOD_END"] = date.today() + + self.assertEqual( + get_time_range_endpoints(form_data={"datasource": "1__table"}, slc=slc), + (TimeRangeEndpoint.INCLUSIVE, TimeRangeEndpoint.EXCLUSIVE), + )