This is an automated email from the ASF dual-hosted git repository.
beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 667eb83 use dynamic time_grains for schema (#14009)
667eb83 is described below
commit 667eb83e33e8f95b70a146a755ae4f672d27d9d8
Author: Elizabeth Thompson <[email protected]>
AuthorDate: Thu Apr 8 13:53:38 2021 -0700
use dynamic time_grains for schema (#14009)
---
superset/charts/schemas.py | 40 ++++++++++++++++++----------------------
1 file changed, 18 insertions(+), 22 deletions(-)
diff --git a/superset/charts/schemas.py b/superset/charts/schemas.py
index 7703df7..3853a7c 100644
--- a/superset/charts/schemas.py
+++ b/superset/charts/schemas.py
@@ -21,7 +21,9 @@ from marshmallow import EXCLUDE, fields, post_load, Schema,
validate
from marshmallow.validate import Length, Range
from marshmallow_enum import EnumField
+from superset import app
from superset.common.query_context import QueryContext
+from superset.db_engine_specs.base import builtin_time_grains
from superset.utils import schema as utils
from superset.utils.core import (
AnnotationType,
@@ -33,6 +35,8 @@ from superset.utils.core import (
TimeRangeEndpoint,
)
+config = app.config
+
#
# RISON/JSON schemas for query parameters
#
@@ -126,26 +130,6 @@ openapi_spec_methods_override = {
}
-TIME_GRAINS = (
- "PT1S",
- "PT1M",
- "PT5M",
- "PT10M",
- "PT15M",
- "PT0.5H",
- "PT1H",
- "P1D",
- "P1W",
- "P1M",
- "P0.25Y",
- "P1Y",
- "1969-12-28T00:00:00Z/P1W", # Week starting Sunday
- "1969-12-29T00:00:00Z/P1W", # Week starting Monday
- "P1W/1970-01-03T00:00:00Z", # Week ending Saturday
- "P1W/1970-01-04T00:00:00Z", # Week ending Sunday
-)
-
-
class ChartEntityResponseSchema(Schema):
"""
Schema for a chart object
@@ -498,7 +482,13 @@ class
ChartDataProphetOptionsSchema(ChartDataPostProcessingOperationOptionsSchem
description="Time grain used to specify time period increments in
prediction. "
"Supports [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations)
"
"durations.",
- validate=validate.OneOf(choices=TIME_GRAINS),
+ validate=validate.OneOf(
+ choices=[
+ i
+ for i in {**builtin_time_grains,
**config["TIME_GRAIN_ADDONS"]}.keys()
+ if i
+ ]
+ ),
example="P1D",
required=True,
)
@@ -796,7 +786,13 @@ class ChartDataExtrasSchema(Schema):
description="To what level of granularity should the temporal column
be "
"aggregated. Supports "
"[ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations)
durations.",
- validate=validate.OneOf(choices=TIME_GRAINS),
+ validate=validate.OneOf(
+ choices=[
+ i
+ for i in {**builtin_time_grains,
**config["TIME_GRAIN_ADDONS"]}.keys()
+ if i
+ ]
+ ),
example="P1D",
allow_none=True,
)