Only do an autoupdate after an ongoing transaction.

This needs at least django 1.9

Fixes: #2248
This commit is contained in:
Oskar Hahn 2016-08-08 07:48:11 +02:00
parent f34621f483
commit ee2f6b500b
2 changed files with 15 additions and 9 deletions

View File

@ -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):

View File

@ -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