Fix config cache key
This commit is contained in:
parent
ab164e4e88
commit
97bd526dd7
@ -38,6 +38,11 @@ class CollectionElement:
|
||||
self.information = information or {}
|
||||
if instance is not None:
|
||||
self.collection_string = instance.get_collection_string()
|
||||
from openslides.core.config import config
|
||||
if self.collection_string == config.get_collection_string():
|
||||
# For config objects we do not work with the pk but with the key.
|
||||
self.id = instance.key
|
||||
else:
|
||||
self.id = instance.pk
|
||||
elif collection_string is not None and id is not None:
|
||||
self.collection_string = collection_string
|
||||
@ -144,8 +149,7 @@ class CollectionElement:
|
||||
# The config instance has to be get from the config element, because
|
||||
# some config values are not in the db.
|
||||
from openslides.core.config import config
|
||||
if (self.collection_string == config.get_collection_string() and
|
||||
isinstance(self.id, str)):
|
||||
if self.collection_string == config.get_collection_string():
|
||||
self.instance = {'key': self.id, 'value': config[self.id]}
|
||||
else:
|
||||
model = self.get_model()
|
||||
|
@ -225,6 +225,22 @@ class TestCollectionElement(TestCase):
|
||||
collection.CollectionElement.from_values('testmodule/model', 1),
|
||||
collection.CollectionElement.from_values('testmodule/other_model', 1))
|
||||
|
||||
def test_config_cache_key(self):
|
||||
"""
|
||||
Test that collection elements for config values do always use the
|
||||
config key as cache key.
|
||||
"""
|
||||
fake_config_instance = MagicMock()
|
||||
fake_config_instance.get_collection_string.return_value = 'core/config'
|
||||
fake_config_instance.key = 'test_config_key'
|
||||
|
||||
self.assertEqual(
|
||||
collection.CollectionElement.from_values('core/config', 'test_config_key').get_cache_key(),
|
||||
'core/config:test_config_key')
|
||||
self.assertEqual(
|
||||
collection.CollectionElement.from_instance(fake_config_instance).get_cache_key(),
|
||||
'core/config:test_config_key')
|
||||
|
||||
|
||||
class TestCollection(TestCase):
|
||||
@patch('openslides.utils.collection.CollectionElement')
|
||||
|
Loading…
Reference in New Issue
Block a user