django-tenant-schemas
django-tenant-schemas copied to clipboard
DB error when deleting tenant with auto_drop_schema = True on tenant model
When deleting a tenant while having auto_drop_schema
set to True
on it Django raises a DB error: ProgrammingError: relation "xxx_xxx" does not exist
.
This gives a dropped schema but the tenant object stays in the DB. I think this happens because the schema is dropped before the call to delete()
on the TenantMixin
. Is this order of events chosen on purpose? Otherwise it would just be a switch of the according lines to solve this.
I just changed the order (delete the object first, then drop the schema) of the lines to test it: now when deleting the tenant using the shell and tenant_context()
the object gets deleted and the schema dropped. When doing the same in the admin app the schema stays. (Maybe managing the tenants from the admin app isn't a good idea anyways...)
Yes, the order is on purpose. It's better to have a "leftover" tenant than a "leftover" schema. If the tenant gets dropped, it will be hard to know that the schema was actually not deleted. Conversely, dropping the schema but not dropping the tenant is not the end of the world and should lead to an easily debugable error state.
I however do not understand why it wouldn't work from the admin. Does it call a different delete function?
@bernardopires @silllli is there any example you can refer to?