Skip to content

fix(sql): revert the Custom SQL metric GROUP BY check from #42199 - #46650

Open
DamianPendrak wants to merge 2 commits into
apache:masterfrom
DamianPendrak:revert/42199-custom-sql-metric-check
Open

DamianPendrak wants to merge 2 commits into
apache:masterfrom
DamianPendrak:revert/42199-custom-sql-metric-check

Conversation

@DamianPendrak

@DamianPendrak DamianPendrak commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

Reverts the check added in #42199, which rejected every Custom SQL metric without an aggregate whenever the query had a GROUP BY.

That check also blocks valid SQL that worked in 6.1, as reported in #46641 (thanks @MikolajBalcerek):

  • constants, e.g. 'WIP' next to COUNT(*), grouped by channel;
  • expressions over grouped columns only, e.g. (this_week - last_week) / last_week grouped by franchise, this_week, last_week.

Every heuristic version of this check risks blocking valid SQL (quoted names, subqueries, dialect rules), while it only improved the error for queries the database rejects anyway. So this removes it; the database's own error applies again, as before #42199. A later follow-up can improve the message for #38913 by adding a hint to the database's GROUP BY error instead of checking in advance.

has_aggregate() stays in superset/sql/parse.py, since other code uses it. The error tests are removed, and a regression test covers constants and grouped-column expressions.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

  1. Create a chart grouped by a dimension with a Custom SQL metric 'WIP' (plus COUNT(*)): it runs.
  2. Group by franchise, this_week, last_week with the metric (this_week - last_week) / last_week: it runs.
  3. Automated: pytest tests/unit_tests/models/helpers_test.py -k custom_sql_metric.

ADDITIONAL INFORMATION

…ROUP BY (apache#42199)

The check added in apache#42199 rejected every Custom SQL metric without an
aggregate whenever the query had a GROUP BY. That also blocks valid SQL
that worked in 6.1, such as constants ('WIP') and expressions over grouped
columns only ((this_week - last_week) / last_week). Remove the check and
its error tests, and add a regression test for those cases.

has_aggregate() stays in superset/sql/parse.py: other code uses it.

Fixes apache#46641

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codeant-ai-for-open-source

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: 177a54897182

…s.pot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MikolajBalcerek MikolajBalcerek 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.

Closing my partial fix in favour of revert to fix all the blocked charts cases :)

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.79%. Comparing base (e017ab8) to head (0942726).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #46650      +/-   ##
==========================================
- Coverage   65.80%   65.79%   -0.01%     
==========================================
  Files        3146     3146              
  Lines      220020   220012       -8     
  Branches    52111    52106       -5     
==========================================
- Hits       144781   144766      -15     
- Misses      71807    71816       +9     
+ Partials     3432     3430       -2     
Flag Coverage Δ
hive 33.64% <ø> (+<0.01%) ⬆️
mysql 51.82% <ø> (-0.01%) ⬇️
postgres 51.85% <ø> (-0.01%) ⬇️
presto 35.33% <ø> (+<0.01%) ⬆️
python 52.15% <ø> (-0.01%) ⬇️
sqlite 51.55% <ø> (-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.

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

i18n Namespace | Anything related to localization size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Superset 7.0 rc] SQL metric check blocks previously valid queries using groupby

2 participants