django-tenant-schemas icon indicating copy to clipboard operation
django-tenant-schemas copied to clipboard

DB error when deleting tenant with auto_drop_schema = True on tenant model

Open silllli opened this issue 8 years ago • 3 comments

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.

silllli avatar Jun 02 '16 10:06 silllli

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...)

silllli avatar Jun 02 '16 12:06 silllli

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 avatar May 06 '17 19:05 bernardopires

@bernardopires @silllli is there any example you can refer to?

tobiasgoecke avatar Jun 01 '21 13:06 tobiasgoecke