Skip to content

fix(explore): stop metric edits from bleeding across metrics with duplicate optionNames#41208

Open
jesperct wants to merge 4 commits into
apache:masterfrom
jesperct:fix/metrics-shared-optionname-edit
Open

fix(explore): stop metric edits from bleeding across metrics with duplicate optionNames#41208
jesperct wants to merge 4 commits into
apache:masterfrom
jesperct:fix/metrics-shared-optionname-edit

Conversation

@jesperct

@jesperct jesperct commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

SUMMARY

Editing one custom (adhoc) metric could silently rewrite other metrics on the same chart. When a chart's saved metrics include two adhoc metrics that share an optionName (which can happen, for example after duplicating a metric), editing one of them overwrote every metric with that optionName — both the label and the definition snapped to the edited one.

Root cause: the metric controls match an edit back to its metric by optionName, but nothing guaranteed optionName was unique. This fixes it where metrics are loaded into the control (coerceMetrics / coerceAdhocMetrics): a metric whose optionName collides with an earlier one is given a fresh optionName, so each metric keeps a unique identity. That both heals already-affected saved charts and prevents the behavior going forward. The fix is applied to the drag-and-drop metric control used by Explore and to the legacy metrics control, which share the same matching logic.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

BEFORE:
sc102554-before
editing one metric's aggregate (SUM → MAX) also changes the second metric, leaving two identical MAX(num) metrics.

AFTER:
sc102554-after

only the edited metric changes; the second metric stays AVG(num).

TESTING INSTRUCTIONS

  1. Open a chart whose form_data holds two adhoc metrics on the same column that share an optionName (this is the state a duplicated metric can leave behind).
  2. Edit one metric (e.g. change its aggregate or label) and save.
    • Before: both metrics change together.
    • After: only the edited metric changes; the other is untouched.
  3. Unit coverage: DndMetricSelect.test.tsx and MetricsControl.test.tsx assert that loading two metrics with a duplicate optionName yields unique identities so an edit touches only one.

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

@netlify

netlify Bot commented Jun 18, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit f1071aa
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a3942b508d3b20008b69576
😎 Deploy Preview https://deploy-preview-41208--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 64.36%. Comparing base (9765967) to head (dfc4266).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
...ontrols/DndColumnSelectControl/DndMetricSelect.tsx 90.90% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #41208   +/-   ##
=======================================
  Coverage   64.36%   64.36%           
=======================================
  Files        2653     2653           
  Lines      144868   144881   +13     
  Branches    33424    33428    +4     
=======================================
+ Hits        93241    93255   +14     
+ Misses      49954    49953    -1     
  Partials     1673     1673           
Flag Coverage Δ
javascript 68.56% <94.11%> (+<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.

@jesperct jesperct force-pushed the fix/metrics-shared-optionname-edit branch 2 times, most recently from dfaeced to 80ff8d1 Compare June 19, 2026 17:54
@jesperct jesperct marked this pull request as ready for review June 19, 2026 21:32
@dosubot dosubot Bot added the explore:metrics Related to metrics of Explore label Jun 19, 2026

@bito-code-review bito-code-review Bot 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.

Code Review Agent Run #168057

Actionable Suggestions - 1
  • superset-frontend/src/explore/components/controls/MetricControl/MetricsControl.test.tsx - 1
Review Details
  • Files reviewed - 4 · Commit Range: d39ebbf..80ff8d1
    • superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndMetricSelect.test.tsx
    • superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndMetricSelect.tsx
    • superset-frontend/src/explore/components/controls/MetricControl/MetricsControl.test.tsx
    • superset-frontend/src/explore/components/controls/MetricControl/MetricsControl.tsx
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

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 documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines +159 to +166
expect(onChange).toHaveBeenCalledWith(
expect.arrayContaining([
expect.objectContaining({
aggregate: AGGREGATES.AVG,
label: 'AVG(value)',
}),
]),
);

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.

Incomplete test assertion

The assertion only verifies the untouched AVG(value) metric is preserved. It does not verify the edited SUM(value)→MAX(value) metric was actually saved. If the save operation fails to propagate the edit, this test passes incorrectly. Per BITO.md rule [6262], tests must validate actual behavior, not just partial outcomes.

Code Review Run #168057


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Strengthened the assertion to also check the edited metric saved as MAX(value), so a dropped edit can't pass on the surviving AVG alone. dfc4266.

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.

The reviewer's suggestion is appropriate. The test currently only verifies that the untouched metric is preserved, but it fails to confirm that the intended edit (SUM(value) to MAX(value)) was successfully applied. Strengthening the assertion to check for the presence of the updated metric ensures the test validates the full behavior of the save operation.

@bito-code-review

bito-code-review Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #246b45

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 80ff8d1..dfc4266
    • superset-frontend/src/explore/components/controls/MetricControl/MetricsControl.test.tsx
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

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 documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

jesperct added 4 commits June 22, 2026 11:12
…ss metrics

Metrics are matched by optionName when an edit is saved, but a saved
chart can carry two adhoc metrics sharing the same optionName (e.g. born
from a duplicated metric). Editing one then overwrote every metric with
that optionName. coerceAdhocMetrics now regenerates colliding optionNames
on load so each metric keeps a unique identity.
The drag-and-drop metric control (used by current Explore) matches edits
by optionName the same way the legacy control does, so it shares the
same bug: editing one of two metrics with a duplicate optionName rewrote
both. Apply the same uniqueness fix in coerceMetrics, verified live.
… other survives

Strengthen the shared-optionName regression test to also assert the
targeted metric saved as MAX(value), so a silently-dropped edit can't
make the test pass on the untouched metric alone.
@jesperct jesperct force-pushed the fix/metrics-shared-optionname-edit branch from f1bc1da to f1071aa Compare June 22, 2026 14:12
@bito-code-review

bito-code-review Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #098e65

Actionable Suggestions - 0
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset-frontend/src/explore/components/controls/MetricControl/MetricsControl.test.tsx - 1
Review Details
  • Files reviewed - 4 · Commit Range: 8c7dc61..f1071aa
    • superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndMetricSelect.test.tsx
    • superset-frontend/src/explore/components/controls/DndColumnSelectControl/DndMetricSelect.tsx
    • superset-frontend/src/explore/components/controls/MetricControl/MetricsControl.test.tsx
    • superset-frontend/src/explore/components/controls/MetricControl/MetricsControl.tsx
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

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 documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

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

Labels

explore:metrics Related to metrics of Explore size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant