#2698: Custom default managers interfere with delete operations
------------------------------+---------------------------------------------
Reporter: anonymous | Owner: adrian
Type: defect | Status: new
Priority: normal | Milestone:
Component: Database wrapper | Version: SVN
Severity: normal | Keywords:
------------------------------+---------------------------------------------
In our model, we have a Story class, with a boolean 'deleted'
attribute. We defined a custom default manager to return all of the
stories that are not deleted, so that most of the code on the site will
not have to deal with filtering out the deleted stories (there's another
custom manager called with_deleted for those code paths that need to see
the deleted stories as well).
The problem comes up when deleting a user. The deletion code iterates
the user's stories to delete them, but uses the default manager, so
stories with deleted=1 are not found. So (ironically) any stories
marked with the 'deleted' field are not actually deleted when the user
is removed. This prevents the user from being deleted, because the
story table still has a foreign key reference to the user table, and
MySQL prevents the user record from being deleted.
The docs for custom managers say: "it's generally a good idea for the
first Manager to be relatively unfiltered". But it seems that any
filtering in the default manager will interfere with cascading deletes.
If the default manager does any filtering at all, then deleting an object
may fail because its related objects will not all be deleted, and the
database's referential integrity will prevent the deletion. When looking
for related obejcts to delete, you have to always get all of them. No
filtering allowed.
--
Ticket URL: <http://code.djangoproject.com/ticket/2698>
Django <http://code.djangoproject.org/>
The web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---