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

   ### SUMMARY
   
   This PR fixes a bug where system tags (owner, type, favorited_by) were being 
processed as custom tags during dashboard/chart updates, causing duplicate key 
violations.
   
   **Key Changes:**
   1. **Filter system tags from custom tag updates** - The `update_tags()` 
function now filters out system tags before creating custom tagged objects. 
System tags are automatically managed by SQLAlchemy event listeners and should 
not be manually assigned.
   
   2. **Rename `get_tag` to `get_or_create_tag`** - Clearer function name that 
explicitly indicates the get-or-create pattern.
   
   3. **Add race condition handling** - Added `IntegrityError` handling in 
`get_or_create_tag()` to gracefully handle concurrent tag creation attempts.
   
   4. **Update Tag model unique constraint** - Changed from single-column 
unique constraint on `name` to composite unique constraint on `(name, type)` to 
allow the same tag name with different types.
   
   **Root Cause:**
   When updating a dashboard/chart with tag IDs in the payload (e.g., `"tags": 
[10, 3]`), the system was attempting to create custom tagged objects for ALL 
tag IDs, including system tags. This caused the error when trying to create a 
custom tag with the same name as an existing system tag (e.g., 
"type:dashboard").
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A - Backend fix
   
   ### TESTING INSTRUCTIONS
   1. Create a dashboard
   2. Note the system tags automatically created (type:dashboard, owner:X)
   3. Try to update the dashboard with a PUT request including those system tag 
IDs in the tags array:
      ```json
      {
        "dashboard_title": "Test",
        "tags": [<system_tag_id>, <system_tag_id>]
      }
      ```
   4. **Before**: Would fail with `IntegrityError: duplicate key value violates 
unique constraint "tag_name_key"`
   5. **After**: Successfully updates, system tags are filtered out
   
   ### ADDITIONAL INFORMATION
   - [x] Has associated issue: Related to tag system bugs
   - [ ] Required feature flags: None
   - [ ] Changes UI: No
   - [ ] Includes DB Migration: No (model change only, migration in separate PR)
   - [ ] Introduces new feature or API: No
   - [ ] Removes existing feature or API: No
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   Co-Authored-By: Claude <[email protected]>


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