﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8168	Need another Pre Delete Signal Type (feature)	magneto	nobody	"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?

"		closed	Core (Other)	dev		duplicate	signals		Design decision needed	0	0	0	0	0	0
