Skip to content

fix(dashboard): stop list-valued order_by_cols from 500-ing the datasets API - #45700

Open
Dmitry-Kucher wants to merge 3 commits into
apache:masterfrom
Dmitry-Kucher:fix/sqla-order-by-cols-list
Open

Dmitry-Kucher wants to merge 3 commits into
apache:masterfrom
Dmitry-Kucher:fix/sqla-order-by-cols-list

Conversation

@Dmitry-Kucher

Copy link
Copy Markdown
Contributor

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)
  • Introduces new feature or API
  • Removes existing feature or API

…ets API

GET /api/v1/dashboard/<id>/datasets fails for any dashboard holding a chart
whose order_by_cols contains a raw list and no usable query_context, which
leaves every widget on that dashboard 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. The
form_data fallback in data_for_slices passed anything non-adhoc straight
through, so a raw list reached set.update() and raised.

superset.common.form_data_query_context already tolerates both encodings when
building orderby, which is why chart data still renders and only the
dashboard-level datasets call fails. Apply the same tolerance through a
_column_param_name() helper that accepts either encoding, takes the column half
of the pair, and skips anything unrecognised instead of failing the request.

This 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.

Co-Authored-By: AIST code-assistant https://virtuman.com
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 4de194789b46

@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.03%. Comparing base (230d9b0) to head (4de1947).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #45700   +/-   ##
=======================================
  Coverage   85.03%   85.03%           
=======================================
  Files        3080     3080           
  Lines      209437   209451   +14     
  Branches    49385    49389    +4     
=======================================
+ Hits       178095   178111   +16     
+ Misses      27960    27959    -1     
+ Partials     3382     3381    -1     
Flag Coverage Δ
hive 34.19% <7.14%> (-0.01%) ⬇️
mysql 52.02% <28.57%> (-0.01%) ⬇️
postgres 52.03% <28.57%> (-0.01%) ⬇️
presto 35.85% <7.14%> (-0.01%) ⬇️
python 87.96% <100.00%> (+<0.01%) ⬆️
sqlite 51.78% <28.57%> (-0.01%) ⬇️
unit 82.90% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rebenitez1802 rebenitez1802 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Verified the raw-list order_by_cols case fails on master and is fixed here, the JSON-string encoding now resolves to the sort column, and the other column params behave the same as before. Thanks for the fix!

rusackas and others added 2 commits October 28, 2026 21:52
Bring in upstream CI fixes and rerun checks after the previous GitHub API rate-limit failures. SQLA models suite: 123 passed. Pre-commit passed for both PR files.
@Dmitry-Kucher

Copy link
Copy Markdown
Contributor Author

@gabotorresruiz This PR has approval from rebenitez1802 and is updated with master. CI is green, and all 123 SQLA model unit tests pass locally. Could you take a look when you have a chance? Thanks!

@gabotorresruiz gabotorresruiz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Dmitry-Kucher, and sorry for the wait. I ran models_test.py at 4de1947 (123 of 123), then put the old comprehension back: 6 of the 7 new cases fail, and the seventh (malformed JSON) is already tolerated on master. I also checked that bracketed names such as [2024] and [Revenue] in groupby still reach the trimmed metadata. CI is green. LGTM!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants