Skip to content

Commit

Permalink
feat: Allows dynamic type on viz migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed May 8, 2023
1 parent b4371f6 commit 5e9fe8d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions superset/migrations/shared/migrate_viz/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class MigrateViz:
rename_keys: Dict[str, str] = {}
source_viz_type: str
target_viz_type: str
has_x_axis_control: bool = False

def __init__(self, form_data: str) -> None:
self.data = try_load_json(form_data)
Expand Down Expand Up @@ -92,6 +93,9 @@ def _migrate_temporal_filter(self, rv_data: Dict[str, Any]) -> None:
if not granularity_sqla:
return

if self.has_x_axis_control:
rv_data["x_axis"] = granularity_sqla

temporal_filter = {
"clause": "WHERE",
"subject": granularity_sqla,
Expand All @@ -106,18 +110,23 @@ def _migrate_temporal_filter(self, rv_data: Dict[str, Any]) -> None:
temporal_filter["subject"] = granularity_sqla["label"]
temporal_filter["sqlExpression"] = granularity_sqla["sqlExpression"]

rv_data["adhoc_filters"] = rv_data.get("adhoc_filters", []) + [temporal_filter]
rv_data["adhoc_filters"] = (rv_data.get("adhoc_filters") or []) + [
temporal_filter
]

@classmethod
def upgrade_slice(cls, slc: Slice) -> Slice:
clz = cls(slc.params)
slc.viz_type = cls.target_viz_type
form_data_bak = copy.deepcopy(clz.data)

clz._pre_action()
clz._migrate()
clz._post_action()

# viz_type depends on the migration and should be set after its execution
# because a source viz can be mapped to different target viz types
slc.viz_type = clz.target_viz_type

# only backup params
slc.params = json.dumps({**clz.data, FORM_DATA_BAK_FIELD_NAME: form_data_bak})

Expand Down

0 comments on commit 5e9fe8d

Please sign in to comment.