Merge pull request #22454 from edx/feanil/handle_pickling_failure

Feanil/handle pickling failure
This commit is contained in:
Feanil Patel
2019-12-09 11:44:14 -05:00
committed by GitHub
4 changed files with 49 additions and 20 deletions

View File

@@ -207,7 +207,15 @@ class BlockStructureStore(object):
"""
Deserializes the given data and returns the parsed block_structure.
"""
block_relations, transformer_data, block_data_map = zunpickle(serialized_data)
try:
block_relations, transformer_data, block_data_map = zunpickle(serialized_data)
except Exception:
# Somehow failed to de-serialized the data, assume it's corrupt.
bs_model = self._get_model(root_block_usage_key)
logger.exception(u"BlockStructure: Failed to load data from cache for %s", bs_model)
raise BlockStructureNotFound(bs_model.data_usage_key)
return BlockStructureFactory.create_new(
root_block_usage_key,
block_relations,

View File

@@ -56,11 +56,17 @@ def get_edx_api_data(api_config, resource, api, resource_id=None, querystring=No
cached = cache.get(cache_key)
if cached:
cached_response = zunpickle(cached)
if fields:
cached_response = get_fields(fields, cached_response)
try:
cached_response = zunpickle(cached)
except Exception: # pylint: disable=broad-except
# Data is corrupt in some way.
log.warning("Data for cache is corrupt for cache key %s", cache_key)
cache.delete(cache_key)
else:
if fields:
cached_response = get_fields(fields, cached_response)
return cached_response
return cached_response
try:
endpoint = getattr(api, resource)