-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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: cannot delete a database if team member has SQL editor tab that uses that db #19243
fix: cannot delete a database if team member has SQL editor tab that uses that db #19243
Conversation
f036a6c
to
c176a4e
Compare
Codecov Report
@@ Coverage Diff @@
## master #19243 +/- ##
==========================================
- Coverage 66.58% 66.56% -0.03%
==========================================
Files 1677 1677
Lines 64238 64238
Branches 6538 6538
==========================================
- Hits 42773 42758 -15
- Misses 19766 19781 +15
Partials 1699 1699
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
c176a4e
to
9e670ae
Compare
899eea4
to
c138e95
Compare
❗ Please consider rebasing your branch to avoid db migration conflicts. |
2 similar comments
❗ Please consider rebasing your branch to avoid db migration conflicts. |
❗ Please consider rebasing your branch to avoid db migration conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Can you add the migration script runtime values to the description too?
c138e95
to
65985bf
Compare
@eschutho Sorry about that, added to the description. |
❗ Please consider rebasing your branch to avoid db migration conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question about the down revision change in the other migration.
superset/migrations/versions/58df9d617f14_add_on_saved_query_delete_tab_state_.py
Outdated
Show resolved
Hide resolved
e862de8
to
0f79c12
Compare
) | ||
|
||
with op.batch_alter_table("table_schema") as batch_op: | ||
batch_op.drop_constraint( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the sqlite errors here, it's because sqlite doesn't support foreign key deletion and actually these foreign key lookups are returning None. So you could either check that the foreign key exists before deleting it or only run these foreign key deletions if the db is not sqlite like:
if not isinstance(bind.dialect, SQLiteDialect):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, in order to support sqlite, can we do that? Or do we need to rename this table, create the new one with the proper constraints and then delete the old one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just not run the drop_constraint if the dialect is sqlite or if the constraint isn't found. I prefer the latter b/c it's more specific and descriptive, but either would work. There are a lot of instance of checking for SQLiteDialect in the codebase already. If you go with the latter, though, it would be something like this:
table_schema_id_constraint = generic_find_fk_constraint_name("table_schema", {"id"}, "dbs", insp)
if table_schema_id_constraint:
batch_op.drop_constraint(table_schema_id_constraint, type_="foreignkey")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue in this case is that I'm dropping the constraint here to add it again, with a different setup.
Will it work if the field has more than one constraint? seems odd to me, but if it does, then will do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Sqlite has foreign keys turned off by default, so if you do the lookup and it's not found, then you should be fine.
ffe55cb
to
7dc0fe0
Compare
Looks great. Thanks @diegomedina248! |
Thank you! |
…uses that db (apache#19243) * fix: update sql lab models constraints to support db deletion * update with master * solve db migration conflict * fix tests (cherry picked from commit 350f21d)
🏷️ preset:2022.13 |
…uses that db (apache#19243) * fix: update sql lab models constraints to support db deletion * update with master * solve db migration conflict * fix tests
SUMMARY
The
TabState
model has foreign key constraints on it that are not properly handled when the referred rows are deleted.This causes, for instance, that a database fails to be deleted if the user has an SQL Lab editor opened with a query referencing that database.
This PR adds a database migration with
ondelete
instructions to properly handle cascading deletes when needed.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION
Runtime estimates results (benchmark_migration.py)