From ffde065e51a928f5b24d73847e63d0a45baf976b Mon Sep 17 00:00:00 2001 From: hdahme Date: Sun, 19 Jan 2025 21:31:43 -0800 Subject: [PATCH 1/5] Fixing the API, pulling viz_type out of params properly --- superset/commands/chart/create.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/superset/commands/chart/create.py b/superset/commands/chart/create.py index 84b3aa29411e..9be80254abe3 100644 --- a/superset/commands/chart/create.py +++ b/superset/commands/chart/create.py @@ -43,6 +43,16 @@ class CreateChartCommand(CreateMixin, BaseCommand): def __init__(self, data: dict[str, Any]): self._properties = data.copy() + # Extract viz_type from params if it exists + if 'params' in self._properties: + try: + import json + params = json.loads(self._properties['params']) + if 'viz_type' in params: + self._properties['viz_type'] = params['viz_type'] + except json.JSONDecodeError as ex: + exceptions.append(ex) + @transaction(on_error=partial(on_error, reraise=ChartCreateFailedError)) def run(self) -> Model: self.validate() From f3c4f1ae0ab218d14b3fabe1d44bc381f5487367 Mon Sep 17 00:00:00 2001 From: hdahme Date: Sun, 19 Jan 2025 21:37:45 -0800 Subject: [PATCH 2/5] changing remotes" From 8ca1d4e25dec2b8205366f7a82224d6173c84fa4 Mon Sep 17 00:00:00 2001 From: hdahme Date: Tue, 21 Jan 2025 14:52:09 -0800 Subject: [PATCH 3/5] Linting and fixing tests --- superset/commands/chart/create.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/superset/commands/chart/create.py b/superset/commands/chart/create.py index 9be80254abe3..1e83f4701785 100644 --- a/superset/commands/chart/create.py +++ b/superset/commands/chart/create.py @@ -43,15 +43,14 @@ class CreateChartCommand(CreateMixin, BaseCommand): def __init__(self, data: dict[str, Any]): self._properties = data.copy() - # Extract viz_type from params if it exists - if 'params' in self._properties: + if self._properties.get('params'): try: import json params = json.loads(self._properties['params']) if 'viz_type' in params: self._properties['viz_type'] = params['viz_type'] except json.JSONDecodeError as ex: - exceptions.append(ex) + raise ex @transaction(on_error=partial(on_error, reraise=ChartCreateFailedError)) def run(self) -> Model: From 832802332a4f1baaf0d347ec3578cee30c744e26 Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 29 May 2026 20:54:12 -0700 Subject: [PATCH 4/5] fix(chart): clean up viz_type extraction from params in CreateChartCommand - Move json import to module level (from superset.utils import json) - Remove redundant try/except that only re-raised the exception - Add isinstance(params, dict) guard to prevent TypeError when params JSON is not an object (e.g. a list or string) - Fix single-quote style to match project conventions Co-Authored-By: Claude Sonnet 4.6 --- superset/commands/chart/create.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/superset/commands/chart/create.py b/superset/commands/chart/create.py index 1e83f4701785..be3f86b93b52 100644 --- a/superset/commands/chart/create.py +++ b/superset/commands/chart/create.py @@ -34,6 +34,7 @@ from superset.commands.utils import get_datasource_by_id from superset.daos.chart import ChartDAO from superset.daos.dashboard import DashboardDAO +from superset.utils import json from superset.utils.decorators import on_error, transaction logger = logging.getLogger(__name__) @@ -43,14 +44,10 @@ class CreateChartCommand(CreateMixin, BaseCommand): def __init__(self, data: dict[str, Any]): self._properties = data.copy() - if self._properties.get('params'): - try: - import json - params = json.loads(self._properties['params']) - if 'viz_type' in params: - self._properties['viz_type'] = params['viz_type'] - except json.JSONDecodeError as ex: - raise ex + if params_str := self._properties.get("params"): + params = json.loads(params_str) + if isinstance(params, dict) and "viz_type" in params: + self._properties["viz_type"] = params["viz_type"] @transaction(on_error=partial(on_error, reraise=ChartCreateFailedError)) def run(self) -> Model: From bae380f04fa3d5e17d6840e65f29268ddfcd06ef Mon Sep 17 00:00:00 2001 From: Evan Date: Fri, 29 May 2026 21:23:10 -0700 Subject: [PATCH 5/5] fix(chart): prefer explicit viz_type over params-derived value If a caller supplies viz_type at the top level and also embeds it in the params JSON, the explicit field should take precedence. Switching from a direct assignment to setdefault() ensures the params value is only used when no top-level viz_type was provided. Co-Authored-By: Claude Sonnet 4.6 --- superset/commands/chart/create.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/superset/commands/chart/create.py b/superset/commands/chart/create.py index be3f86b93b52..e3d3ea93f330 100644 --- a/superset/commands/chart/create.py +++ b/superset/commands/chart/create.py @@ -47,7 +47,9 @@ def __init__(self, data: dict[str, Any]): if params_str := self._properties.get("params"): params = json.loads(params_str) if isinstance(params, dict) and "viz_type" in params: - self._properties["viz_type"] = params["viz_type"] + # Only fall back to params when no top-level viz_type was supplied; + # an explicit top-level field takes precedence. + self._properties.setdefault("viz_type", params["viz_type"]) @transaction(on_error=partial(on_error, reraise=ChartCreateFailedError)) def run(self) -> Model: