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

   <!---
   Please write the PR title following the conventions at 
https://www.conventionalcommits.org/en/v1.0.0/
   Example:
   fix(dashboard): load charts correctly
   -->
   
   ### SUMMARY
   <!--- Describe the change below, including rationale and design decisions -->
   When editing a dataset, if both the SQL and a new metric are changed at the 
same time, Superset throws a "metric already exists" validation error.
   
   This happens because onConfirmSave():
   
   Sends a first PUT to save the updated SQL and metrics
   
   Then, if the SQL has changed, sends a second PUT after syncing columns — but 
reuses the outdated currentDatasource.metrics without refreshed IDs
   
   As a result, the new metrics appear to lack ids, so the backend treats them 
as duplicates based on name.
   
   This fix ensures that, after the first save and before the second PUT, we 
fetch the updated dataset and assign the correct metric IDs, preventing the 
duplication error.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   We would get this error when both the SQL and a new metric are changed at 
the same time:
   
   
![image](https://github.com/user-attachments/assets/83e950e5-74d1-4709-b03a-8e18d65a4830)
   
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   After the fix, try editing the SQL query and adding a new metric would cause 
no errors:
   
   
![image](https://github.com/user-attachments/assets/7eb74d24-798d-4ac3-bcb9-dce139cc631c)
   
   
![image](https://github.com/user-attachments/assets/71a6b7d7-4598-4a16-94dc-f28bed7d6c67)
   
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] 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
   


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