#8168 closed (duplicate)
Need another Pre Delete Signal Type (feature)
Reported by: | magneto | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | signals | |
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
the Pre delete signal is not all its cracked up to be ...
there should be another signal which is 'pre_prepare_for_delete'
This issuse is this
suppose i have 2 apps, all foreignkeyed to a user
#################### #Ap 1 class M1(models.Model): user = models.ForeignKey(User) very_transactional_stuff = models.CharFeld(max_length = 4) def on_delete_user(sender, instance, *args, **kwargs): ASSIGN_TO_ROOT_ON_DELETE, created = User.object.get_or_create(username = 'UserDeleted') for m in M1.objects.filter(user = instance) m.user = ASSIGN_TO_ROOT_ON_DELETE m.save() signals.pre_delete.connect(on_delete_user, sender = User) #################### # Ap 2 class M1(models.Model): user = models.ForeignKey(User) very_transactional_stuff_two = models.CharFeld(max_length = 4) def on_delete_user(sender, instance, *args, **kwargs): ASSIGN_TO_ROOT_ON_DELETE, created = User.object.get_or_create(username = 'UserDeleted') for m in M1.objects.filter(user = instance) m.user = ASSIGN_TO_ROOT_ON_DELETE m.save() signals.pre_delete.connect(on_delete_user, sender = User)
Saddly this is what happens on a delete
- all the 'dependant' objects are obtained
# db.models.base.py Line 423 # Find all the objects than need to be deleted. seen_objs = CollectedObjects() self._collect_sub_objects(seen_objs) # Actually delete the objects. delete_objects(seen_objs)
- pre_delete is called
# db.models.query Line 810 # Pre-notify all instances to be deleted. for pk_val, instance in items: signals.pre_delete.send(sender=cls, instance=instance)
- uses the objects in the first step and DELETED them all, even after we have just 'reassinged' them (as the initial filter matched)
# db.models.query Lines 810 - 830
I propose another signal that is the 'pre_prepare_for_delete' that slips into
# db.models.base.py Line 423 #first fire off the prepared signal signals.pre_prepare_for_delete.send(sender=self.__class__, instance=self) # Find all the objects than need to be deleted. seen_objs = CollectedObjects() self._collect_sub_objects(seen_objs) # Actually delete the objects. delete_objects(seen_objs)
Thoughts?
Change History (5)
comment:1 by , 16 years ago
milestone: | → post-1.0 |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:2 by , 16 years ago
milestone: | post-1.0 |
---|
comment:3 by , 15 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
While the requested feature is different, the use-case is addressed by #7539.
Note:
See TracTickets
for help on using tickets.
Milestone post-1.0 deleted