Dmitry-Kucher opened a new pull request, #45700:
URL: https://github.com/apache/superset/pull/45700
### SUMMARY
`GET /api/v1/dashboard/<id>/datasets` fails for a dashboard that holds a
chart whose `order_by_cols` contains a raw list, when that chart has no usable
`query_context`. Every widget on the dashboard is then left without datasource
metadata:
```
File "superset/connectors/sqla/models.py", in data_for_slices
column_names.update(_columns)
TypeError: unhashable type: 'list'
```
`order_by_cols` holds `[column, ascending]` pairs. They are canonically
stored as JSON strings (`'["col", false]'`), but older writers persisted raw
lists, and such charts exist in real deployments. The `form_data` fallback in
`data_for_slices` passed every non-adhoc entry straight through, so a raw list
reached `set.update()`.
`superset.common.form_data_query_context` already accepts both encodings
when it builds `orderby`, which is why chart data still renders and only the
dashboard datasets call fails. This PR applies the same tolerance through a
`_column_param_name()` helper: it accepts either encoding, takes the column
half of the pair (which may itself be an adhoc column), and skips anything
unrecognised instead of failing the request. A string that isn't valid JSON is
still treated as a plain column name, since bracketed names such as `[Revenue]`
are legal.
It also fixes the canonical encoding. A JSON string used to be added to
`column_names` verbatim, so it never matched a real column, and the ordering
column was dropped from the trimmed metadata. It now resolves to the column
name.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (backend).
### TESTING INSTRUCTIONS
```
pytest tests/unit_tests/connectors/sqla/models_test.py -k order_by_cols
```
The parametrized test covers both encodings, an adhoc column as the pair
head, non-ASCII column names, and junk entries (non-string head, empty pair,
malformed JSON). Most cases fail without the fix.
Manual: pick a table chart with "Sort by" set, set its
`params.order_by_cols` to a raw list (e.g. `[["some_col", false]]`) and clear
its `query_context`, then open a dashboard containing it. Before: the datasets
request fails and the charts don't load. After: the dashboard loads.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in
[SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
--
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]