Merge pull request #2473 from ostcar/fix_config_cache_key

Fix config cache key.
This commit is contained in:
Norman Jäckel 2016-10-01 13:02:48 +02:00 committed by GitHub
commit 5879702354
2 changed files with 23 additions and 3 deletions

View File

@ -38,7 +38,12 @@ class CollectionElement:
self.information = information or {}
if instance is not None:
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:
self.collection_string = collection_string
self.id = id
@ -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()

View File

@ -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')