Skip to content

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

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

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

Conversation

@jesperct

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: editing one metric's aggregate (SUM → MAX) also changes the second metric, leaving two identical MAX(num) metrics.
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

jesperct added 2 commits June 18, 2026 14:19
…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.
@netlify

netlify Bot commented Jun 18, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit ef0e30b
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a3441314b289b0008ce55f9
😎 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.33%. Comparing base (c218dc4) to head (ef0e30b).
⚠️ Report is 9 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.33%   64.33%           
=======================================
  Files        2651     2651           
  Lines      144766   144779   +13     
  Branches    33401    33405    +4     
=======================================
+ Hits        93131    93145   +14     
+ Misses      49965    49964    -1     
  Partials     1670     1670           
Flag Coverage Δ
javascript 68.49% <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.

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.

1 participant