This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new dd67772ad9 fix: Improving handling for tag relationship when deleting 
assets (#29117)
dd67772ad9 is described below

commit dd67772ad90846fdadd87f1d63df1589fa614934
Author: Vitor Avila <[email protected]>
AuthorDate: Mon Jun 10 20:14:26 2024 -0300

    fix: Improving handling for tag relationship when deleting assets (#29117)
---
 superset/models/dashboard.py | 7 ++++---
 superset/models/slice.py     | 5 +++--
 superset/models/sql_lab.py   | 7 ++++---
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/superset/models/dashboard.py b/superset/models/dashboard.py
index 6e6989bf9e..98baa83278 100644
--- a/superset/models/dashboard.py
+++ b/superset/models/dashboard.py
@@ -150,11 +150,12 @@ class Dashboard(AuditMixinNullable, ImportExportMixin, 
Model):
     )
     tags = relationship(
         "Tag",
-        overlaps="objects,tag,tags,tags",
+        overlaps="objects,tag,tags",
         secondary="tagged_object",
-        primaryjoin="and_(Dashboard.id == TaggedObject.object_id)",
-        secondaryjoin="and_(TaggedObject.tag_id == Tag.id, "
+        primaryjoin="and_(Dashboard.id == TaggedObject.object_id, "
         "TaggedObject.object_type == 'dashboard')",
+        secondaryjoin="and_(TaggedObject.tag_id == Tag.id)",
+        passive_deletes=True,
     )
     published = Column(Boolean, default=False)
     is_managed_externally = Column(Boolean, nullable=False, default=False)
diff --git a/superset/models/slice.py b/superset/models/slice.py
index bc89b5b7c4..e4c6a35ae8 100644
--- a/superset/models/slice.py
+++ b/superset/models/slice.py
@@ -104,9 +104,10 @@ class Slice(  # pylint: disable=too-many-public-methods
         "Tag",
         secondary="tagged_object",
         overlaps="objects,tag,tags",
-        primaryjoin="and_(Slice.id == TaggedObject.object_id)",
-        secondaryjoin="and_(TaggedObject.tag_id == Tag.id, "
+        primaryjoin="and_(Slice.id == TaggedObject.object_id, "
         "TaggedObject.object_type == 'chart')",
+        secondaryjoin="and_(TaggedObject.tag_id == Tag.id)",
+        passive_deletes=True,
     )
     table = relationship(
         "SqlaTable",
diff --git a/superset/models/sql_lab.py b/superset/models/sql_lab.py
index 3c26c6c12f..4abed73436 100644
--- a/superset/models/sql_lab.py
+++ b/superset/models/sql_lab.py
@@ -415,10 +415,11 @@ class SavedQuery(
     tags = relationship(
         "Tag",
         secondary="tagged_object",
-        overlaps="tags",
-        primaryjoin="and_(SavedQuery.id == TaggedObject.object_id)",
-        secondaryjoin="and_(TaggedObject.tag_id == Tag.id, "
+        overlaps="objects,tag,tags",
+        primaryjoin="and_(SavedQuery.id == TaggedObject.object_id, "
         "TaggedObject.object_type == 'query')",
+        secondaryjoin="and_(TaggedObject.tag_id == Tag.id)",
+        passive_deletes=True,
     )
 
     export_parent = "database"

Reply via email to