Skip to content

Comments

fix(tags): expire tag relationship after deleting all tagged objects#38163

Open
rusackas wants to merge 1 commit intomasterfrom
fix-36074-bulk-untag-error
Open

fix(tags): expire tag relationship after deleting all tagged objects#38163
rusackas wants to merge 1 commit intomasterfrom
fix-36074-bulk-untag-error

Conversation

@rusackas
Copy link
Member

SUMMARY

Fixes #36074

When removing all tagged objects from a tag via the Edit Tag UI, users encountered the error "Error Updating Tag". The root cause was a SQLAlchemy session state issue where the Tag model's objects relationship still held references to deleted TaggedObject instances after they were removed.

Root Cause:

  1. UpdateTagCommand.run() calls TagDAO.create_tag_relationship()
  2. create_tag_relationship() deletes TaggedObject entries via delete_tagged_object()
  3. After deletion, tag.objects relationship still references the deleted objects
  4. When db.session.add(self._model) is called, SQLAlchemy encounters the deleted objects and raises: "Instance has been deleted. Use the make_transient() function to send this object back to the transient state."

Fix:
Call db.session.expire(tag, ["objects"]) after deleting tagged objects to clear the stale references from the relationship. This allows SQLAlchemy to properly reload the relationship on next access.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Not applicable - this is a backend bug fix with no UI changes.

TESTING INSTRUCTIONS

  1. Enable the tagging feature flag if not already enabled
  2. Create a new tag
  3. Tag multiple objects (e.g., 2-3 saved queries or dashboards)
  4. Navigate to the tag and click Edit
  5. Remove ALL tagged objects from the tag
  6. Click Save
  7. Verify the tag saves successfully without errors

Before fix: Step 6 would fail with "Error Updating Tag"
After fix: Step 6 succeeds and the tag is updated with no tagged objects

ADDITIONAL INFORMATION

  • Has associated issue: Bulk Untag not working : "Error Updating Tag" #36074
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • 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

Fixes #36074

When removing all tagged objects from a tag, the Tag model's 'objects'
relationship still held references to deleted TaggedObject instances.
This caused a SQLAlchemy error when the tag was later added to the
session: "Instance has been deleted. Use the make_transient() function
to send this object back to the transient state."

The fix calls db.session.expire(tag, ["objects"]) after deleting tagged
objects to clear the stale references from the relationship, allowing
the session to properly reload the relationship on next access.

Added a regression test that verifies removing all tagged objects from
a tag works without errors.

Co-Authored-By: Claude <noreply@anthropic.com>
@bito-code-review
Copy link
Contributor

bito-code-review bot commented Feb 22, 2026

Code Review Agent Run #d530e4

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 4911dcc..4911dcc
    • superset/daos/tag.py
    • tests/unit_tests/tags/commands/update_test.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ 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

@dosubot
Copy link

dosubot bot commented Feb 22, 2026

Related Documentation

Checked 0 published document(s) in 2 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added the change:backend Requires changing the backend label Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bulk Untag not working : "Error Updating Tag"

1 participant