Commit ef108333 by Calen Pennington

Handle malformed keys in MixedModuleStore configuration

parent 1e27f177
...@@ -40,7 +40,11 @@ class MixedModuleStore(ModuleStoreWriteBase): ...@@ -40,7 +40,11 @@ class MixedModuleStore(ModuleStoreWriteBase):
try: try:
self.mappings[CourseKey.from_string(course_id)] = store_name self.mappings[CourseKey.from_string(course_id)] = store_name
except InvalidKeyError: except InvalidKeyError:
try:
self.mappings[SlashSeparatedCourseKey.from_deprecated_string(course_id)] = store_name self.mappings[SlashSeparatedCourseKey.from_deprecated_string(course_id)] = store_name
except InvalidKeyError:
log.exception("Invalid MixedModuleStore configuration. Unable to parse course_id %r", course_id)
continue
if 'default' not in stores: if 'default' not in stores:
raise Exception('Missing a default modulestore in the MixedModuleStore __init__ method.') raise Exception('Missing a default modulestore in the MixedModuleStore __init__ method.')
...@@ -50,8 +54,8 @@ class MixedModuleStore(ModuleStoreWriteBase): ...@@ -50,8 +54,8 @@ class MixedModuleStore(ModuleStoreWriteBase):
if is_xml: if is_xml:
# restrict xml to only load courses in mapping # restrict xml to only load courses in mapping
store['OPTIONS']['course_ids'] = [ store['OPTIONS']['course_ids'] = [
course_id course_key.to_deprecated_string()
for course_id, store_key in mappings.iteritems() for course_key, store_key in self.mappings.iteritems()
if store_key == key if store_key == key
] ]
self.modulestores[key] = create_modulestore_instance( self.modulestores[key] = create_modulestore_instance(
......
...@@ -38,6 +38,7 @@ class TestMixedModuleStore(LocMapperSetupSansDjango): ...@@ -38,6 +38,7 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
MONGO_COURSEID = 'MITx/999/2013_Spring' MONGO_COURSEID = 'MITx/999/2013_Spring'
XML_COURSEID1 = 'edX/toy/2012_Fall' XML_COURSEID1 = 'edX/toy/2012_Fall'
XML_COURSEID2 = 'edX/simple/2012_Fall' XML_COURSEID2 = 'edX/simple/2012_Fall'
BAD_COURSE_ID = 'edX/simple'
modulestore_options = { modulestore_options = {
'default_class': DEFAULT_CLASS, 'default_class': DEFAULT_CLASS,
...@@ -53,7 +54,8 @@ class TestMixedModuleStore(LocMapperSetupSansDjango): ...@@ -53,7 +54,8 @@ class TestMixedModuleStore(LocMapperSetupSansDjango):
'mappings': { 'mappings': {
XML_COURSEID1: 'xml', XML_COURSEID1: 'xml',
XML_COURSEID2: 'xml', XML_COURSEID2: 'xml',
MONGO_COURSEID: 'default' BAD_COURSE_ID: 'xml',
MONGO_COURSEID: 'default',
}, },
'stores': { 'stores': {
'xml': { 'xml': {
......
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