From 3115db58363659dccc6e68830280f5a1563a598c Mon Sep 17 00:00:00 2001 From: 0x29a Date: Tue, 13 Dec 2022 09:22:53 +0100 Subject: [PATCH] feat: implement falling back to HiddenBlock --- xmodule/modulestore/mongo/base.py | 11 ++++++++++- xmodule/modulestore/split_mongo/split.py | 11 ++++++++++- xmodule/modulestore/xml.py | 11 ++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/xmodule/modulestore/mongo/base.py b/xmodule/modulestore/mongo/base.py index 6e9f4c19fd..5f9abf6f93 100644 --- a/xmodule/modulestore/mongo/base.py +++ b/xmodule/modulestore/mongo/base.py @@ -521,7 +521,16 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo if default_class is not None: module_path, _, class_name = default_class.rpartition('.') - class_ = getattr(import_module(module_path), class_name) + try: + class_ = getattr(import_module(module_path), class_name) + except ImportError: + fallback_module_path = "xmodule.hidden_block" + fallback_class_name = "HiddenDescriptor" + log.exception( + "Failed to import the default store class. " + f"Falling back to {fallback_module_path}.{fallback_class_name}" + ) + class_ = getattr(import_module(fallback_module_path), fallback_class_name) self.default_class = class_ else: self.default_class = None diff --git a/xmodule/modulestore/split_mongo/split.py b/xmodule/modulestore/split_mongo/split.py index 58e6af9816..159642c136 100644 --- a/xmodule/modulestore/split_mongo/split.py +++ b/xmodule/modulestore/split_mongo/split.py @@ -656,7 +656,16 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase): if default_class is not None: module_path, __, class_name = default_class.rpartition('.') - class_ = getattr(import_module(module_path), class_name) + try: + class_ = getattr(import_module(module_path), class_name) + except ImportError: + fallback_module_path = "xmodule.hidden_block" + fallback_class_name = "HiddenDescriptor" + log.exception( + "Failed to import the default store class. " + f"Falling back to {fallback_module_path}.{fallback_class_name}" + ) + class_ = getattr(import_module(fallback_module_path), fallback_class_name) self.default_class = class_ else: self.default_class = None diff --git a/xmodule/modulestore/xml.py b/xmodule/modulestore/xml.py index 4213ae6eec..b965872b4f 100644 --- a/xmodule/modulestore/xml.py +++ b/xmodule/modulestore/xml.py @@ -335,7 +335,16 @@ class XMLModuleStore(ModuleStoreReadBase): self.default_class = None else: module_path, _, class_name = default_class.rpartition('.') - class_ = getattr(import_module(module_path), class_name) + try: + class_ = getattr(import_module(module_path), class_name) + except ImportError: + fallback_module_path = "xmodule.hidden_block" + fallback_class_name = "HiddenDescriptor" + log.exception( + "Failed to import the default store class. " + f"Falling back to {fallback_module_path}.{fallback_class_name}" + ) + class_ = getattr(import_module(fallback_module_path), fallback_class_name) self.default_class = class_ # All field data will be stored in an inheriting field data.