Wednesday, January 31, 2018

Re: A question of signals and ATOMIC_REQUESTS

It seems that your inference is correct

https://stackoverflow.com/a/41522066/214892

On Wednesday, January 31, 2018 at 12:54:29 AM UTC-5, Me Sulphur wrote:
When ATOMIC_REQUESTS=True is set, are ORM signals - post_save and
pre_save - also executed within the transaction?  Per my inference, they
seem be to a part of the transaction.

Assuming my inference is correct, then consider the following code


@receiver(post_save, sender=MyModel)
def log_and_notify_change(sender, instance, created, **kwargs):
     if not created:
         old_copy = MyModel.objects.get(id=instance.id)
         diff_fn(old_copy, new_copy)


Since Postgresql only supports READ COMMITTED, implying that reading a
row inside a transaction should always return the older value. However,
in the code above, old_copy always has updated values meaning that the
signal was executed outside transaction (after it was committed.)

Is this the correct behavior? I tried to reason by looking at the code
but again not sure.

Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cf15a5eb-e822-4251-9f1b-f31b1aebde5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment