From 20379c14c0b3dc7d0e3611d2888c829a37e0ffd9 Mon Sep 17 00:00:00 2001 From: Sanford Student Date: Tue, 23 Aug 2016 15:10:08 -0400 Subject: [PATCH] check for null doc --- .../modulestore/split_mongo/mongo_connection.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py b/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py index dd34cb5f6c..f8be210202 100644 --- a/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py +++ b/common/lib/xmodule/xmodule/modulestore/split_mongo/mongo_connection.py @@ -21,6 +21,7 @@ except ImportError: DJANGO_AVAILABLE = False import dogstats_wrapper as dog_stats_api +import logging from contracts import check, new_contract from mongodb_proxy import autoretry_read @@ -31,6 +32,7 @@ from xmodule.mongo_utils import connect_to_mongodb, create_collection_index new_contract('BlockData', BlockData) +log = logging.getLogger(__name__) def get_cache(alias): @@ -315,7 +317,7 @@ class MongoConnection(object): """ Get the structure from the persistence mechanism whose id is the given key. - This method will use a cached version of the structure if it is availble. + This method will use a cached version of the structure if it is available. """ with TIMER.timer("get_structure", course_context) as tagger_get_structure: cache = CourseStructureCache() @@ -328,6 +330,12 @@ class MongoConnection(object): with TIMER.timer("get_structure.find_one", course_context) as tagger_find_one: doc = self.structures.find_one({'_id': key}) + if doc is None: + log.warning( + "doc was None when attempting to retrieve structure for item with key %s", + unicode(key) + ) + return None tagger_find_one.measure("blocks", len(doc['blocks'])) structure = structure_from_mongo(doc, course_context) tagger_find_one.sample_rate = 1