From 6b4e03032884d4ea8bbb3c5fe234d17f11157cf7 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Tue, 19 Nov 2024 16:10:09 -0800 Subject: [PATCH] add try except --- reflex/config.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/reflex/config.py b/reflex/config.py index ef48895ea..9a86e0f26 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -825,6 +825,17 @@ def get_config(reload: bool = False) -> Config: return Config(app_name="") rxconfig = importlib.import_module(constants.Config.MODULE) return rxconfig.config + except Exception: + sys.path.extend(sys_path) + # only import the module if it exists. If a module spec exists then + # the module exists. + spec = find_spec(constants.Config.MODULE) + if not spec: + # we need this condition to ensure that a ModuleNotFound error is not thrown when + # running unit/integration tests or during `reflex init`. + return Config(app_name="") + rxconfig = importlib.import_module(constants.Config.MODULE) + return rxconfig.config finally: sys.path.clear() sys.path.extend(sys_path)