Any way to force Django to commit a write so another process can read the correct data from DB?

312 views
Skip to first unread message

Stodge

unread,
Jul 27, 2016, 10:27:34 AM7/27/16
to Django users
My website uses a combination of Django + Java apps to function. For this particular problem, a record is deleted from the DB via a TastyPie resource DELETE operation. A Django signal post_delete handleris invoked, which submits a DELETE request to Jetty running in the Java app. The Java app then performs a query using Hibernate.

What appears to be happening is that Django thinks the record was deleted:

DynamicVolume.objects.filter(user=instance.user).count()

Returns ZERO.

However, the Java app thinks the record still exists unless I make it sleep for several seconds before asking Hibernate to query the DB.

I've tried forcing Hibernate to clear its cache with no success. Is there a way to force Django to commit the deletion (flush the cache)?

Thanks

Constantine Covtushenko

unread,
Jul 27, 2016, 3:47:10 PM7/27/16
to django...@googlegroups.com
Hi Stodge,

As said in Django current version of documentation, 'post_delete' signal is sent after record is deleted. This means also that transaction is closed at that moment. And DB should not has deleted instance any more.

I have double checked the Django code and can say that Django send that signal just before transaction is committed.
So technically instance should be inside DB for Hibernate processing.

I can suggest you to create a custom signal and send it after transaction closed.
That should solve your problem.

Regards,

--
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...@googlegroups.com.
To post to this group, send email to django...@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/e76d5cfa-f4bc-41db-a322-0d44aa0719dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luis Zárate

unread,
Jul 27, 2016, 8:36:12 PM7/27/16
to django...@googlegroups.com
I thing java apps have a cache and it is java who is not looking in the database.  I was a similar problem with hirbernate time ago. But I never solved other person solved it and I don't know how.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK52boWeFYGOhk0CL%2BoEimreb2k%2BgFwL2rBb0imoPbmfpwo5Yw%40mail.gmail.com.

> For more options, visit https://groups.google.com/d/optout.
>

--
"La utopía sirve para caminar" Fernando Birri



Mike Dewhirst

unread,
Jul 27, 2016, 8:55:22 PM7/27/16
to django...@googlegroups.com
On 28/07/2016 5:46 AM, Constantine Covtushenko wrote:
> Hi Stodge,
>
> As said in Django current version of documentation
> <https://docs.djangoproject.com/en/1.9/ref/signals/#post-delete>,
> 'post_delete' signal is sent after record is deleted. This means also
> that transaction is closed at that moment. And DB should not has deleted
> instance any more.
>
> I have double checked the Django code and can say that Django send that
> signal just before transaction is committed.

Is this a Django bug?

Is it the same for post_save?

Mike
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> <https://groups.google.com/d/msgid/django-users/e76d5cfa-f4bc-41db-a322-0d44aa0719dd%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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...@googlegroups.com
> <mailto:django-users...@googlegroups.com>.
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@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/CAK52boWeFYGOhk0CL%2BoEimreb2k%2BgFwL2rBb0imoPbmfpwo5Yw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAK52boWeFYGOhk0CL%2BoEimreb2k%2BgFwL2rBb0imoPbmfpwo5Yw%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Constantine Covtushenko

unread,
Jul 28, 2016, 10:00:07 AM7/28/16
to django...@googlegroups.com
Hi Mike,

It is not a bug.
It is just how it works.

Regards

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.

epool...@gmail.com

unread,
Jul 28, 2016, 6:22:49 PM7/28/16
to Django users
Reply all
Reply to author
Forward
0 new messages