From ee2f6b500be0c43f2d0cb218c92d26c4d337e924 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Mon, 8 Aug 2016 07:48:11 +0200 Subject: [PATCH] Only do an autoupdate after an ongoing transaction. This needs at least django 1.9 Fixes: #2248 --- openslides/utils/autoupdate.py | 22 ++++++++++++++-------- requirements_production.txt | 2 +- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/openslides/utils/autoupdate.py b/openslides/utils/autoupdate.py index 3bb64a2d7..5cddda1f4 100644 --- a/openslides/utils/autoupdate.py +++ b/openslides/utils/autoupdate.py @@ -5,6 +5,7 @@ from asgiref.inmemory import ChannelLayer from channels import Channel, Group from channels.auth import channel_session_user, channel_session_user_from_http from django.apps import apps +from django.db import transaction from django.utils import timezone from ..users.auth import AnonymousUser @@ -108,14 +109,19 @@ def inform_changed_data(instance, is_deleted=False): # Instance has no method get_root_rest_element. Just ignore it. pass else: - try: - Channel('autoupdate.send_data').send({ - 'collection_string': root_instance.get_collection_string(), - 'pk': root_instance.pk, - 'is_deleted': is_deleted and instance == root_instance, - 'dispatch_uid': root_instance.get_access_permissions().get_dispatch_uid()}) - except ChannelLayer.ChannelFull: - pass + # If currently there is an open database transaction, then the following + # function is only called, when the transaction is commited. If there + # is currently no transaction, then the function is called immediately. + def send_autoupdate(): + try: + Channel('autoupdate.send_data').send({ + 'collection_string': root_instance.get_collection_string(), + 'pk': root_instance.pk, + 'is_deleted': is_deleted and instance == root_instance, + 'dispatch_uid': root_instance.get_access_permissions().get_dispatch_uid()}) + except ChannelLayer.ChannelFull: + pass + transaction.on_commit(send_autoupdate) def inform_changed_data_receiver(sender, instance, **kwargs): diff --git a/requirements_production.txt b/requirements_production.txt index b4b3a6107..adb203614 100644 --- a/requirements_production.txt +++ b/requirements_production.txt @@ -1,5 +1,5 @@ # Requirements for OpenSlides in production in alphabetical order -Django>=1.8,<1.11,!=1.10.0 +Django>=1.9,<1.11,!=1.10.0 beautifulsoup4>=4.5,<4.6 channels>=0.15,<1.0 djangorestframework>=3.2.0,<3.5