-
Notifications
You must be signed in to change notification settings - Fork 14.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Improving handling for tag relationship when deleting assets #29117
Conversation
I'm checking if I can add some tests around this flow to prevent a regression |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #29117 +/- ##
==========================================
+ Coverage 60.48% 64.65% +4.16%
==========================================
Files 1931 518 -1413
Lines 76236 37492 -38744
Branches 8568 0 -8568
==========================================
- Hits 46114 24239 -21875
+ Misses 28017 13253 -14764
+ Partials 2105 0 -2105
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Adding tests here would be complex, since it requires having assets (dashboards and charts) with the same ID and forcing the ID during the asset creation is atypical and could impact other tests. I wanted to be extra sure the object_id = Column(
Integer,
ForeignKey("dashboards.id"),
ForeignKey("slices.id"),
ForeignKey("saved_query.id"),
) I did some tests running Superset with a PSQL DB with query logging enabled, and the deletion queries look correct (they're including a filter for the
We could also assess a bigger alternative which would be changing the |
Given that the DELETE statements look good, and the complexity of the alternative solutions, I think this is solid for now. Let's merge to fix the issue at hand and we can reconsider other approaches in the future. |
@Vitor-Avila I'm not sure this is the right approach, i.e., historically errors of the form,
typically suggest there's something borked within our ORM. |
It seemed like the right longer term solution might be to have one bridge table for each tag relationship (?) |
@john-bodley 100% agreed! This is currently happening because the statement to delete entries from the I worked on this as an attempt to have a fast fix in place (the issue is pretty simple to reproduce, make sure you have a dashboard and a chart with the same ID, assign tags/owners to both and try to delete one). Since it seems this solution didn't fully solve the issue just yet, I just submitted an alternative approach that I believe is better: #29229 |
SUMMARY
The relationship between the
tagged_objects
table and the asset table (for example,dashboard
) is a combination of theobject_id
andobject_type
. While this relationship works properly when displaying tags/etc, when deleting an asset SQLAlchemy was trying to runDELETE FROM tagged_object WHERE tagged_object.tag_id = ? AND tagged_object.object_id = ?
which would delete more rows then it should (it's missing another filter forobject_type
), causing the operation to fail with an error:This PR adds the
passive_deletes=True
argument to therelationship
, so that the cascade delete is handled by the DB (based on the constraints).BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
No UI changes.
TESTING INSTRUCTIONS
owners
to both assets.ADDITIONAL INFORMATION