From 692502c0fb8f6ef1eacd1388a0ca772993e8d794 Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 28 Jan 2014 15:54:00 -0500 Subject: [PATCH] Don't cache falsy values --- .../lib/xmodule/xmodule/modulestore/loc_mapper_store.py | 4 ++++ .../xmodule/modulestore/tests/test_location_mapper.py | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py b/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py index ce22793651..7e00abfdac 100644 --- a/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py +++ b/common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py @@ -404,6 +404,8 @@ class LocMapperStore(object): """ Get the course Locator for this old course id """ + if not old_course_id: + return None entry = self.cache.get(old_course_id) if entry is not None: if published: @@ -428,6 +430,8 @@ class LocMapperStore(object): """ For quick lookup of courses """ + if not old_course_id: + return self.cache.set(old_course_id, (published_course_locator, draft_course_locator)) def _cache_location_map_entry(self, old_course_id, location, published_usage, draft_usage): diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py b/common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py index 90da230e76..a0e869d9fe 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py @@ -80,8 +80,8 @@ class TestLocationMapper(unittest.TestCase): Request translation, check package_id, block_id, and branch """ prob_locator = loc_mapper().translate_location( - old_style_course_id, - location, + old_style_course_id, + location, published= (branch=='published'), add_entry_if_missing=add_entry ) @@ -114,7 +114,7 @@ class TestLocationMapper(unittest.TestCase): new_style_package_id = '{}.geek_dept.{}.baz_run'.format(org, course) block_map = { - 'abc123': {'problem': 'problem2'}, + 'abc123': {'problem': 'problem2'}, 'def456': {'problem': 'problem4'}, 'ghi789': {'problem': 'problem7'}, } @@ -139,7 +139,7 @@ class TestLocationMapper(unittest.TestCase): # add a distractor course (note that abc123 has a different translation in this one) distractor_block_map = { - 'abc123': {'problem': 'problem3'}, + 'abc123': {'problem': 'problem3'}, 'def456': {'problem': 'problem4'}, 'ghi789': {'problem': 'problem7'}, }