diff --git a/openslides/utils/collection.py b/openslides/utils/collection.py index 661007d00..6993218b2 100644 --- a/openslides/utils/collection.py +++ b/openslides/utils/collection.py @@ -506,8 +506,11 @@ def get_model_from_collection_string(collection_string): pass else: _models_to_collection_string[get_collection_string()] = model - - return _models_to_collection_string[collection_string] + try: + model = _models_to_collection_string[collection_string] + except KeyError: + raise ValueError('Invalid message. A valid collection_string is missing.') + return model def get_single_element_cache_key(collection_string, id): diff --git a/tests/unit/utils/test_collection.py b/tests/unit/utils/test_collection.py index 065c7683b..9bb292e9b 100644 --- a/tests/unit/utils/test_collection.py +++ b/tests/unit/utils/test_collection.py @@ -58,7 +58,7 @@ class TestGetModelFromCollectionString(TestCase): self.assertEqual(projector_model, Projector) def test_unknown_app(self): - with self.assertRaises(KeyError): + with self.assertRaises(ValueError): collection.get_model_from_collection_string('invalid/model')