Dmitry-Kucher opened a new issue, #43420:
URL: https://github.com/apache/superset/issues/43420
### Bug description
Since #43027, the Table and AG Grid Table "Show summary" row rewrites
**every** Simple (adhoc) metric's aggregate to the `totals_aggregate` control's
value, which defaults to `SUM`. The control offers only Sum and Average and is
`clearable: false`, so there is no way to keep a metric's own aggregation, and
existing charts silently changed behaviour on upgrade.
Two consequences:
**1. Charts break outright.** A `COUNT_DISTINCT` over a non-numeric column
becomes `SUM` over that column. On Postgres with a `uuid` column the query is
rejected:
```
psycopg2.errors.UndefinedFunction: function sum(uuid) does not exist
LINE 1: SELECT sum(contract_id) AS "Кол-во", SUM(contract_amount/100...
HINT: No function matches the given name and argument types.
```
**2. Charts that don't break show wrong numbers.** The same rewrite on a
numeric column produces `SUM(order_id)` for a `COUNT_DISTINCT(order_id)`
metric, or a sum where the metric asked for `AVG`/`MIN`/`MAX`. Nothing errors;
the summary row is just wrong. This is the part I'd flag as the more serious
half — it is silent.
The main query is unaffected, so only the summary row is wrong, which makes
it easy to miss.
### How to reproduce
1. Table chart, Aggregate mode, one dimension.
2. Add a metric `COUNT_DISTINCT(some_uuid_column)`.
3. Enable **Show summary**. Leave **Summary aggregation** at its default.
4. The chart fails with `function sum(uuid) does not exist`.
Swap the uuid for an integer id and the chart renders, with a summary row
showing the sum of the ids rather than a distinct count.
The payload makes it explicit — `queries[0]` is correct, `queries[1]` (the
summary, `columns: []`) is not:
```
queries[0].metrics: SIMPLE | aggregate=COUNT_DISTINCT | col=contract_id
queries[1].metrics: SIMPLE | aggregate=SUM | col=contract_id
```
Sending `queries[0]` alone to `/api/v1/chart/data` returns 200; `queries[1]`
alone returns 400.
### Cause
`getTotalsMetrics` overrides unconditionally:
```ts
export function getTotalsMetrics(metrics, aggregate: 'SUM' | 'AVG') {
return metrics.map(metric =>
isAdhocMetricSimple(metric) ? { ...metric, aggregate } : metric,
);
}
```
and both plugins coerce anything that is not `AVG` into `SUM`:
```ts
const totalsAggregate: TotalsAggregate =
formData.totals_aggregate === 'AVG' ? 'AVG' : 'SUM';
```
so a chart saved before #43027, which has no `totals_aggregate` at all, gets
`SUM`.
Before #43027 the summary query was `{ ...queryObject, columns: [] }` —
metrics kept their own aggregate and the result was correct.
#43027's rationale states the swap is safe because the summary query has no
`GROUP BY`, so each metric is evaluated fresh over all rows. That holds
arithmetically, but it assumes the metric's column is summable and that
replacing the aggregate preserves intent. Neither is true for `COUNT_DISTINCT`,
`COUNT`, `MIN` or `MAX`.
### Suggested fix
Make "keep each metric's own aggregation" an explicit third choice and the
default, so Sum/Average stay available as a deliberate opt-in and pre-#43027
charts behave as before. PR attached.
### Screenshots/recordings
_No response_ — the failure surfaces as a "Database error" card on each
affected
chart carrying the `function sum(uuid) does not exist` text quoted above.
### Superset version
master / latest-dev
### Python version
3.11
### Node version
24 or above
### Browser
Chrome
### Additional context
Introduced by #43027 (`f7a2f0ec50`, 2026-08-13). Still present on `master`
at `f2610e9dca` (2026-08-21) — no follow-up commit has touched
`getTotalsMetrics.ts` or the totals block in either plugin's `buildQuery.ts`.
Found on a production instance after upgrading across that commit: three
previously working charts started returning 400, and a fourth (an `AVG` metric)
had been silently showing a sum in its summary row.
### Checklist
- [x] I have searched Superset docs and Slack and didn't find a solution to
my problem.
- [x] I have searched the GitHub issue tracker and didn't find a similar bug
report.
- [x] I have checked Superset's logs for errors and if I found a relevant
Python stacktrace, I included it here as text in the "additional context"
section.
--
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]