jesperct opened a new pull request, #41208:
URL: https://github.com/apache/superset/pull/41208

   ### 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/after attached below -->
   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:
   - [x] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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]

Reply via email to