Tuesday, July 28, 2015

post_delete and determining if a related object has been deleted

Hey guys,

the post_delete signal is fired before the PK field of the deleted and
all related objects is set to None. This leads to the situation that
one can't determine if a related object has been deleted in a
post_delete handler.

Here's an example:

"Order", "Item" and "LogEntry" are the models. Item has a foreign key
to Order, and LogEntry has a foreign key to Order.

When an Item object is deleted, a new LogEntry object shall be created
and attached to the Item's related Order object.

If the Order object itself is deleted, all post_delete handlers of all
related objects are fired, including Item. Item however stores a new
object with a relation to the *deleted Order* object, which will
result in a constraint error (at least when using transactions in
PostgreSQL, which I do).

pre_delete is no option for me, as the proper objects really have to
be gone in order for the operations to work.

I can see that the behavior has changed 8 years ago:
https://code.djangoproject.com/ticket/5559

Is there any other option I'm missing?

Many greetings,
Stefan Schindler

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/55B73127.4010101%40boxbox.org.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment