diff --git a/superset/commands/chart/create.py b/superset/commands/chart/create.py index 84b3aa29411e..e3d3ea93f330 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,6 +44,13 @@ class CreateChartCommand(CreateMixin, BaseCommand): def __init__(self, data: dict[str, Any]): self._properties = data.copy() + if params_str := self._properties.get("params"): + params = json.loads(params_str) + if isinstance(params, dict) and "viz_type" in params: + # 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: self.validate()