add try except

This commit is contained in:
Khaleel Al-Adhami 2024-11-19 16:10:09 -08:00
parent e0a8e8dedc
commit 6b4e030328

View File

@ -825,6 +825,17 @@ def get_config(reload: bool = False) -> Config:
return Config(app_name="") return Config(app_name="")
rxconfig = importlib.import_module(constants.Config.MODULE) rxconfig = importlib.import_module(constants.Config.MODULE)
return rxconfig.config 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: finally:
sys.path.clear() sys.path.clear()
sys.path.extend(sys_path) sys.path.extend(sys_path)