From b97e643b339a40dddd846f95f9dfc255acc33fb4 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Fri, 2 Nov 2018 05:10:49 +0100 Subject: [PATCH] Fix error on to big change id on websocket connection --- openslides/utils/consumers.py | 10 ++++++++-- tests/integration/utils/test_consumers.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/openslides/utils/consumers.py b/openslides/utils/consumers.py index 88c3818d5..3a7d06aa2 100644 --- a/openslides/utils/consumers.py +++ b/openslides/utils/consumers.py @@ -41,9 +41,15 @@ class SiteConsumer(ProtocollAsyncJsonWebsocketConsumer): await self.channel_layer.group_add('autoupdate', self.channel_name) await self.accept() + if change_id is not None: - data = await get_element_data(self.scope['user'], change_id) - await self.send_json(type='autoupdate', content=data) + try: + data = await get_element_data(self.scope['user'], change_id) + except ValueError: + # When the change_id is to big, do nothing + pass + else: + await self.send_json(type='autoupdate', content=data) async def disconnect(self, close_code: int) -> None: """ diff --git a/tests/integration/utils/test_consumers.py b/tests/integration/utils/test_consumers.py index 3556afc69..66a6c7d18 100644 --- a/tests/integration/utils/test_consumers.py +++ b/tests/integration/utils/test_consumers.py @@ -101,6 +101,17 @@ async def test_connection_with_invalid_change_id(get_communicator): assert connected is False +@pytest.mark.asyncio +async def test_connection_with_to_big_change_id(get_communicator): + await set_config('general_system_enable_anonymous', True) + communicator = get_communicator('change_id=1000000000000') + + connected, __ = await communicator.connect() + + assert connected is True + assert await communicator.receive_nothing() + + @pytest.mark.asyncio async def test_changed_data_autoupdate_off(communicator): await set_config('general_system_enable_anonymous', True)