Fix config cache key
This commit is contained in:
parent
ab164e4e88
commit
97bd526dd7
@ -38,7 +38,12 @@ class CollectionElement:
|
|||||||
self.information = information or {}
|
self.information = information or {}
|
||||||
if instance is not None:
|
if instance is not None:
|
||||||
self.collection_string = instance.get_collection_string()
|
self.collection_string = instance.get_collection_string()
|
||||||
self.id = instance.pk
|
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:
|
elif collection_string is not None and id is not None:
|
||||||
self.collection_string = collection_string
|
self.collection_string = collection_string
|
||||||
self.id = id
|
self.id = id
|
||||||
@ -144,8 +149,7 @@ class CollectionElement:
|
|||||||
# The config instance has to be get from the config element, because
|
# The config instance has to be get from the config element, because
|
||||||
# some config values are not in the db.
|
# some config values are not in the db.
|
||||||
from openslides.core.config import config
|
from openslides.core.config import config
|
||||||
if (self.collection_string == config.get_collection_string() and
|
if self.collection_string == config.get_collection_string():
|
||||||
isinstance(self.id, str)):
|
|
||||||
self.instance = {'key': self.id, 'value': config[self.id]}
|
self.instance = {'key': self.id, 'value': config[self.id]}
|
||||||
else:
|
else:
|
||||||
model = self.get_model()
|
model = self.get_model()
|
||||||
|
@ -225,6 +225,22 @@ class TestCollectionElement(TestCase):
|
|||||||
collection.CollectionElement.from_values('testmodule/model', 1),
|
collection.CollectionElement.from_values('testmodule/model', 1),
|
||||||
collection.CollectionElement.from_values('testmodule/other_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):
|
class TestCollection(TestCase):
|
||||||
@patch('openslides.utils.collection.CollectionElement')
|
@patch('openslides.utils.collection.CollectionElement')
|
||||||
|
Loading…
Reference in New Issue
Block a user