Commit b9b16486 by Nimisha Asthagiri

Update BlockStructure version number

https://openedx.atlassian.net/browse/TNL-4865
Without this change, we get 500 errors when the server tries to
deserialize cached data using a previous data structure.
parent 65bca48e
......@@ -395,6 +395,12 @@ class BlockStructureBlockData(BlockStructure):
Subclass of BlockStructure that is responsible for managing block
and transformer data.
"""
# The latest version of the data structure of this class. Incrementally
# update this value whenever the data structure changes. Dependent storage
# layers can then use this value when serializing/deserializing block
# structures, and invalidating any previously cached/stored data.
VERSION = 1
def __init__(self, root_block_usage_key):
super(BlockStructureBlockData, self).__init__(root_block_usage_key)
......
......@@ -6,7 +6,7 @@ from logging import getLogger
from openedx.core.lib.cache_utils import zpickle, zunpickle
from .block_structure import BlockStructureModulestoreData
from .block_structure import BlockStructureModulestoreData, BlockStructureBlockData
logger = getLogger(__name__) # pylint: disable=C0103
......@@ -126,4 +126,7 @@ class BlockStructureCache(object):
Returns the cache key to use for storing the block structure
for the given root_block_usage_key.
"""
return "root.key." + unicode(root_block_usage_key)
return "v{version}.root.key.{root_usage_key}".format(
version=unicode(BlockStructureBlockData.VERSION),
root_usage_key=unicode(root_block_usage_key),
)
......@@ -4,6 +4,7 @@ Tests for manager.py
from nose.plugins.attrib import attr
from unittest import TestCase
from ..block_structure import BlockStructureBlockData
from ..exceptions import UsageKeyNotInBlockStructure
from ..manager import BlockStructureManager
from ..transformers import BlockStructureTransformers
......@@ -154,6 +155,12 @@ class TestBlockStructureManager(TestCase, ChildrenMapTestMixin):
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
self.assertEquals(TestTransformer1.collect_call_count, 2)
def test_get_collected_version_update(self):
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
BlockStructureBlockData.VERSION += 1
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
self.assertEquals(TestTransformer1.collect_call_count, 2)
def test_clear(self):
self.collect_and_verify(expect_modulestore_called=True, expect_cache_updated=True)
self.bs_manager.clear()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment