"""
I also noticed in db optimization docs that we have explicitly
documented update() and delete() as bypassing signals, and I think we
should honour that.

https://docs.djangoproject.com/en/dev/topics/db/optimization/#use-queryset-update-and-delete
"""

Is this correct for delete? A quick test (A1 is a model which I have hanging 
around - details about it aren't important):

from django.db.models.signals import post_delete

def foo(*args, **kwargs):
    print args, kwargs
post_delete.connect(foo, sender=A1)

A1(dt=datetime.now()).save()
A1.objects.all().delete()

Result:
() {'instance': <A1: A1 object>, 'signal': <django.dispatch.dispatcher.Signal 
object at 0xa47434c>, 'sender': <class 'obj_creation_speed.models.A1'>, 
'using': 'default'}

Search post_delete in django/db/models/deletion.py. Signals seem to be sent, 
even for cascaded deletion.

Personally I don't think post/pre instance changed signals are the way to go if 
you want to do auditing. DB triggers are much more reliable. Some problems with 
the Django signals:
  - All operations do not send signals (bulk_create could easily send signals, 
the instances are available directly in that case, even bulk update could send 
signals per instance - first check if there is a listener, if there is, fetch 
all the updated instances and send signals, if there isn't, then don't fetch 
the instances. You will only pay the price when needed. Not saying this is a 
great idea, but maybe worth a thought).  
  - Proxy (including deferred models) and multitable-inherited models do not 
send signals as you would expect. I have groundwork for how to implement fast 
inherited signals in ticket #16679. The patch in that ticket also makes model 
__init__ much faster in certain common-enough cases. On the other hand, yet 
another cache.
  - If you do anything outside Django Models (raw SQL, dbshell, another 
application accessing the DB) your auditing will not work.
  - The DB triggers approach is faster.

The downside is that you will be programming DB specific triggers, in 
DB-specific language. Schema upgrades are a nightmare.

 - Anssi Kääriäinen

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to