Merge pull request #2256 from ostcar/fix_2248

Only do an autoupdate after an ongoing transaction.
This commit is contained in:
Norman Jäckel 2016-08-16 00:14:15 +02:00 committed by GitHub
commit aea602acb9
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 import Channel, Group
from channels.auth import channel_session_user, channel_session_user_from_http from channels.auth import channel_session_user, channel_session_user_from_http
from django.apps import apps from django.apps import apps
from django.db import transaction
from django.utils import timezone from django.utils import timezone
from ..users.auth import AnonymousUser 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. # Instance has no method get_root_rest_element. Just ignore it.
pass pass
else: else:
try: # If currently there is an open database transaction, then the following
Channel('autoupdate.send_data').send({ # function is only called, when the transaction is commited. If there
'collection_string': root_instance.get_collection_string(), # is currently no transaction, then the function is called immediately.
'pk': root_instance.pk, def send_autoupdate():
'is_deleted': is_deleted and instance == root_instance, try:
'dispatch_uid': root_instance.get_access_permissions().get_dispatch_uid()}) Channel('autoupdate.send_data').send({
except ChannelLayer.ChannelFull: 'collection_string': root_instance.get_collection_string(),
pass '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): def inform_changed_data_receiver(sender, instance, **kwargs):

View File

@ -1,5 +1,5 @@
# Requirements for OpenSlides in production in alphabetical order # 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 beautifulsoup4>=4.5,<4.6
channels>=0.15,<1.0 channels>=0.15,<1.0
djangorestframework>=3.2.0,<3.5 djangorestframework>=3.2.0,<3.5