Opened 9 years ago

Last modified 9 years ago

#26715 closed Uncategorized

Model objects with deferred fields don't send pre_save or post_save signals to receivers with explicit sender — at Version 1

Reported by: Evan Heidtmann Owned by: nobody
Component: Database layer (models, ORM) Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Evan Heidtmann)

Because the objects returned by Model.objects.only(*fields) are of a special object type, and that type is used as the sender for the post_save signal send, these deferred objects never invoke signal handlers that registered with an explicit signal sender.

Something like this should reproduce:

# models.py
class MyModel(models.Model):
     bigfield = models.TextField(null=True, blank=True)

# signals.py
@receiver.register(post_save, sender=models.MyModel)
def mymodel_post_save_handler(sender, **kwargs):
     print "handler called"

# repro code
m = MyModel.objects.create()
# (handler is called)
deferred_m = MyModel.objects.only('id').get(id=m.id)
deferred_m.bigfield = 'yo'
deferred_m.save()
# (handler should be called, but is not)

Happy to produce a proper test app/project if needed.

Evan

Change History (1)

comment:1 by Evan Heidtmann, 9 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top