You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "SEPURI-SAI-KRISHNA (via GitHub)" <gi...@apache.org> on 2026/08/15 14:01:39 UTC
[PR] fix(chart): include Decimal metrics in contribution totals [superset]
SEPURI-SAI-KRISHNA opened a new pull request, #43222:
URL: https://github.com/apache/superset/pull/43222
<!-- PR TITLE: fix(chart): include Decimal metrics in contribution totals -->
### SUMMARY
A `Decimal` metric renders as **0%** in every row of a contribution chart that
uses cross-query totals — no error, just silently wrong numbers.
`ensure_totals_available()` builds the totals dictionary handed to the
`contribution` post-processing operation:
```python
totals = {
col: df[col].sum() for col in df.columns if df[col].dtype.kind in "biufc"
}
```
`dtype.kind in "biufc"` covers bool, signed/unsigned int, float and complex.
It does not cover `object`, which is where `decimal.Decimal` values live —
that is how drivers such as psycopg2 hand back `NUMERIC`/`DECIMAL` columns.
So a Decimal metric never gets a totals entry, and `contribution()` takes the
zero branch:
```python
total = contribution_totals.get(col)
if total is None or total == 0:
contribution_df[rename_col] = 0
```
The values themselves are perfectly summable and divisible — `Series.sum()` on
a Decimal column returns a `Decimal`, and `Decimal / Decimal` is exact. Only
the dtype test excludes them.
This PR replaces the inline dtype check with `_is_summable()`, which keeps the
numeric-kind test and additionally accepts object columns whose inferred value
type is `decimal`. Strings, dicts, datetimes and all-null object columns stay
excluded exactly as before.
Found while reviewing #43203, which fixes a different symptom of the same
"Decimal lives in an object column" root cause in `contribution()` itself. The
two are independent and touch different files.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — backend-only fix.
### TESTING INSTRUCTIONS
```bash
pytest tests/unit_tests/common/test_query_context_processor.py
```
Three tests are added:
| test | asserts |
| --- | --- |
| `test_is_summable_accepts_decimal_columns` | Decimal (with and without nulls) is summable; strings/dicts/datetimes are not — fails on `master` |
| `test_ensure_totals_available_includes_decimal_metrics` | a Decimal metric reaches `contribution_totals`, a string column does not — fails on `master` |
| `test_contribution_uses_decimal_totals_rather_than_zero` | end to end: real percentages with the totals present, zeros without |
The third passes either way by design — it pins the downstream consequence
using explicit totals dicts rather than the builder, documenting exactly what
the missing entry costs.
Manually: on Postgres, build a chart over a `NUMERIC` metric with Contribution
Mode enabled on a viz that computes cross-query totals. On `master` the
contribution column is 0 for every row; with this change it shows the real
percentages.
### 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))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
### CHECKLIST
- [ ] CI checks pass
- [x] Tests added/updated
- [ ] Documentation updated
- [x] PR title follows conventions
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5302568635
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "SEPURI-SAI-KRISHNA (via GitHub)" <gi...@apache.org>.
SEPURI-SAI-KRISHNA commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5565519832
Rebased on master. Flagging a scope change, because the diff now touches a file the original PR had nothing to do with.
**The bug gained a second home while this sat.** #43407 migrated Global Async Queries onto the Global Task Framework and added `_inject_contribution_totals` in `superset/tasks/async_queries.py`, which carries its own copy of the predicate:
```python
totals = {col: df[col].sum() for col in df.columns if df[col].dtype.kind in "biufc"}
```
That function's own docstring says it produces "the same result the synchronous `ensure_totals_available` produces, but reading the cache the prerequisite populated instead of re-running the totals query." With two independent copies of the test, the two paths disagree on identical data: a `NUMERIC` column that psycopg2 hands back as `decimal.Decimal` has an object dtype, so the async path drops the metric from the totals dict and `contribution()` reads back `None` and writes a zero. Same silent 0% as the sync path, reachable only with `GLOBAL_ASYNC_QUERIES` on.
Fixing one and not the other would have left the async path quietly wrong, so this now covers both call sites.
**Sharing the predicate rather than copying it a third time.** `_is_summable` is renamed to `is_summable` and imported by `async_queries.py`. That follows what `normalize_contribution_totals` already does in the same module, a shared helper
living in `query_context_processor.py`, imported by `query_context.py`, so the convention is established rather than invented here. The import is function-local, next to the existing `QueryCacheManager` one, because `async_queries.py` deliberately keeps every `superset.common.*` import out of module scope (they are all under `TYPE_CHECKING`).
**One rebase adaptation worth naming.** `ensure_totals_available` grew a `(queries_needing_totals, totals_idx)` signature and delegates to `prepare_contribution_totals()` when called bare, so the existing test's plain `MagicMock` context no longer unpacked. It uses master's own `_wire_contribution_totals()` helper now instead of hand-rolled wiring.
Verified locally: 94 tests pass across both files, and pre-commit is clean. I also mutation-tested both guards, putting `dtype.kind in "biufc"` back at either call site fails the corresponding test, so neither is passing for an incidental reason.
**On the one red check.** `test-postgres-hive` is red for an infrastructure reason, not a finding against this diff. It failed at 43s in step 6, "Start hadoop and hive", and steps 7-11, Setup Python, Setup Postgres, Start Celery worker, Python unit tests (PostgreSQL), Upload code coverage, were all skipped, so no test ran against this branch at all. The rest of the board is green: 62 passing, 12 skipped, that one failure. The same job passes in roughly four minutes on my other open PRs and on recent master commits. A committer re-running that single job should clear it; I do not have permission to re-run it myself.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas merged PR #43222:
URL: https://github.com/apache/superset/pull/43222
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5323084022
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | a9ed454faae68e4016ae852de3bf8bed5788c476 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6a83cd331c7cf9000840208e |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-43222--superset-docs-preview.netlify.app](https://deploy-preview-43222--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
|<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DcpBDkAwEADAv-yZWCqUH3hGbSuaVLeplRDxd73NYV5ImY8kMANUsGYTaS_e_N0QR8l-vcRzrIXFhLO2jvxhQqnWpcDPYksejFZklWpppG1CRN1jh9rB9wM) |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-43222--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5559160242
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "SEPURI-SAI-KRISHNA (via GitHub)" <gi...@apache.org>.
SEPURI-SAI-KRISHNA commented on code in PR #43222:
URL: https://github.com/apache/superset/pull/43222#discussion_r3789704977
##########
superset/common/query_context_processor.py:
##########
@@ -442,9 +460,7 @@ def ensure_totals_available(
result = self._query_context.get_query_result(totals_query)
df = result.df
- totals = {
- col: df[col].sum() for col in df.columns if df[col].dtype.kind in "biufc"
- }
+ totals = {col: df[col].sum() for col in df.columns if _is_summable(df[col])}
Review Comment:
Thanks, I dug into both cache paths, and the mechanism doesn't apply here.
The per-query data cache key never sees these totals. `QueryObject.cache_key()` strips them explicitly before hashing:
```python
if pp_copy.get("operation") == "contribution" and "options" in pp_copy:
options = dict(pp_copy["options"])
# Remove contribution_totals as it's dynamically calculated
options.pop("contribution_totals", None)
```
The QueryContext cache key does include them, via the `cache_values["queries"]` sync, and `generate_cache_key` does hash through `json_int_dttm_ser`, which turns `Decimal` into `float`, I confirmed `json_int_dttm_ser(Decimal("1.0000000000000000001"))` returns `1.0`. But that cannot collapse two otherwise-distinct keys, because `contribution_totals` is derived from the query definitions that are already in the key. Two contexts that hash alike have identical queries, and identical queries produce identical totals; the field adds no entropy of its own.
The one case where totals vary independently is the underlying data changing between requests. There, this change strictly improves matters: on `master` Decimal totals are absent from the key altogether, so it never varies with them
at all. After this change it varies except beyond float precision. Strictly more sensitive than the status quo, never less.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "SEPURI-SAI-KRISHNA (via GitHub)" <gi...@apache.org>.
SEPURI-SAI-KRISHNA commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5303035100
`test-mysql` failed on `tests/integration_tests/tags/api_tests.py::TestTagApi::test_get_tag` with `AssertionError: assert 'now' == 'a second from now'`, a timing flake in that humanized-timestamp assertion, previously addressed in #25958.
2611 other tests in the job passed.
It's unrelated to this change, which touches only `superset/common/query_context_processor.py` and its unit test. Could a
committer re-run that job?
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5324361277
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers a full AI review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "SEPURI-SAI-KRISHNA (via GitHub)" <gi...@apache.org>.
SEPURI-SAI-KRISHNA commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5450593789
Gentle nudge on this one — it's been open since Aug 15 without a first review.
+134/-3 across two files, 115 of which are tests. A `Decimal` metric renders as **0%** in every row of a contribution chart that uses cross-query totals — no error, just silently wrong numbers.
`ensure_totals_available()` filters totals with `df[col].dtype.kind in "biufc"`, which doesn't cover `object` — and that's where `decimal.Decimal` values live, since drivers like psycopg2 return `NUMERIC`/`DECIMAL` that way. With no totals entry, `contribution()` takes its `total is None` branch and assigns zero.
The values are perfectly summable: `Series.sum()` on a Decimal column returns a `Decimal`, and `Decimal / Decimal` is exact. Only the dtype test excludes them. Strings, dicts, datetimes and all-null object columns stay excluded exactly as before. CI is green (62 passing).
Happy to adjust the helper's shape if you'd rather it live elsewhere.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "SEPURI-SAI-KRISHNA (via GitHub)" <gi...@apache.org>.
SEPURI-SAI-KRISHNA commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5303030423
See the inline thread on `query_context_processor.py` for the detail, the short version is that `QueryObject.cache_key()` already pops `contribution_totals` before hashing, and for the QueryContext key the totals are derived from query
definitions that are themselves in the key, so they add no entropy that could collapse two distinct keys. Relative to `master`, where Decimal totals are absent from the key entirely, this change makes the key strictly more sensitive.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5302584570
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/43222?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `33.33333%` with `4 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 57.23%. Comparing base ([`21ae918`](https://app.codecov.io/gh/apache/superset/commit/21ae918656c808c43df7214a7979f85800f4fc43?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`130d6a1`](https://app.codecov.io/gh/apache/superset/commit/130d6a10c54b1388620d3ea4981f4dbe85fca09c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 13 commits behind head on master.
| [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/43222?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/common/query\_context\_processor.py](https://app.codecov.io/gh/apache/superset/pull/43222?src=pr&el=tree&filepath=superset%2Fcommon%2Fquery_context_processor.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY29tbW9uL3F1ZXJ5X2NvbnRleHRfcHJvY2Vzc29yLnB5) | 33.33% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/43222?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (21ae918) and HEAD (130d6a1). Click for more details.
>
> <details><summary>HEAD has 74 uploads less than BASE</summary>
>
>| Flag | BASE (21ae918) | HEAD (130d6a1) |
>|------|------|------|
>|python|65|1|
>|presto|11|1|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #43222 +/- ##
==========================================
- Coverage 66.65% 57.23% -9.42%
==========================================
Files 2873 2873
Lines 163626 163634 +8
Branches 37767 37768 +1
==========================================
- Hits 109059 93653 -15406
- Misses 52438 69092 +16654
+ Partials 2129 889 -1240
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/43222/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/43222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/43222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/43222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/43222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.11% <33.33%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/43222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `40.11% <33.33%> (-19.15%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/43222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit](https://app.codecov.io/gh/apache/superset/pull/43222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/43222?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #43222:
URL: https://github.com/apache/superset/pull/43222#discussion_r3789510384
##########
superset/common/query_context_processor.py:
##########
@@ -442,9 +460,7 @@ def ensure_totals_available(
result = self._query_context.get_query_result(totals_query)
df = result.df
- totals = {
- col: df[col].sum() for col in df.columns if df[col].dtype.kind in "biufc"
- }
+ totals = {col: df[col].sum() for col in df.columns if _is_summable(df[col])}
Review Comment:
**Suggestion:** The raw `Decimal` totals are injected into query post-processing and then into the query-context cache values. When `cache_key()` hashes those values, `json_int_dttm_ser` converts `Decimal` to `float`, which can collapse distinct high-precision totals to the same cache key. A cached context can therefore be reused for a different total and render incorrect contribution percentages; serialize Decimal values without lossy float conversion or exclude these runtime totals from the context cache key. [cache]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Async chart responses can use stale contribution totals.
- ❌ High-precision Decimal contribution percentages become incorrect.
- ⚠️ Affected flow requires query-context caching and precision loss.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=6620cad75d1c41769752787981aafe87&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=6620cad75d1c41769752787981aafe87&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/common/query_context_processor.py
**Line:** 463:463
**Comment:**
*Cache: The raw `Decimal` totals are injected into query post-processing and then into the query-context cache values. When `cache_key()` hashes those values, `json_int_dttm_ser` converts `Decimal` to `float`, which can collapse distinct high-precision totals to the same cache key. A cached context can therefore be reused for a different total and render incorrect contribution percentages; serialize Decimal values without lossy float conversion or exclude these runtime totals from the context cache key.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43222&comment_hash=ce28f73b230b16efccc2660d74c04383f9acdec145d8c1e6a03c6ec81fe5900f&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43222&comment_hash=ce28f73b230b16efccc2660d74c04383f9acdec145d8c1e6a03c6ec81fe5900f&reaction=dislike'>👎</a>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5302589258
<!-- Bito Reply -->
The flagged issue is correct. When `Decimal` values are included in the query context and subsequently hashed for caching, the `json_int_dttm_ser` serializer converts them to `float`. This lossy conversion can cause distinct `Decimal` totals to hash to the same cache key, leading to incorrect cached contribution percentages.
To resolve this, you should ensure `Decimal` values are serialized to strings or another high-precision format during cache key generation, or exclude these runtime totals from the cache key entirely. A common approach is to update the serializer to handle `Decimal` types explicitly by converting them to strings, which preserves precision.
There are no other comments on this PR to address.
**superset/common/query_context_processor.py**
```
def _is_summable(series: pd.Series) -> bool:
"""
Whether a column holds values the contribution totals can be summed over.
A dtype-kind test alone is not enough. `decimal.Decimal` metrics -- how
drivers such as psycopg2 hand back NUMERIC/DECIMAL columns -- are stored
with an object dtype, so they fall outside the numeric kinds even though
they sum and divide perfectly well. Omitting them leaves the totals
dictionary without an entry for the metric, and `contribution()` then
reads back `None` and writes a zero contribution instead of the real
percentage.
"""
if series.dtype.kind in "biufc":
return True
return infer_dtype(series, skipna=True) == "decimal"
```
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(chart): include Decimal metrics in contribution totals [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #43222:
URL: https://github.com/apache/superset/pull/43222#issuecomment-5615985292
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org