rusackas opened a new pull request, #40536:
URL: https://github.com/apache/superset/pull/40536
### SUMMARY
Adopts and fixes #31929 (originally by @hdahme, whose fork was subsequently
archived).
When creating a chart via the API, the `viz_type` field was not being
extracted from the JSON-encoded `params` string. This meant that charts created
programmatically with `params` set (but without an explicit top-level
`viz_type`) ended up with a blank/wrong chart type.
**Changes in `superset/commands/chart/create.py`:**
- In `CreateChartCommand.__init__`, if `params` is present, parse it and
copy `viz_type` into the top-level properties so the model gets the correct
chart type.
- Moved `import json` to module level using `from superset.utils import
json` (project convention).
- Removed the vacuous `try/except JSONDecodeError as ex: raise ex`
antipattern — let the exception propagate naturally.
- Added `isinstance(params, dict)` guard to prevent `TypeError` when the
`params` JSON is not an object (e.g. an array or scalar).
### TESTING INSTRUCTIONS
```bash
pytest tests/integration_tests/charts/commands_tests.py -k "viz_type" -v
```
The integration test at `tests/integration_tests/charts/commands_tests.py`
already covers the expected behaviour: a chart created with
`params={"viz_type": "new_viz_type"}` should have `chart.viz_type ==
"new_viz_type"`.
### ADDITIONAL INFORMATION
- [x] Has associated issue: closes #31929 (adopts abandoned PR)
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]