From a3cbfefb221349ff36242a38760fae0e1a1b522d Mon Sep 17 00:00:00 2001 From: Elijah Ahianyo Date: Tue, 4 Jun 2024 11:48:52 -0700 Subject: [PATCH] [REF-2602] Do not suppress import errors in rxconfig (#3434) --- reflex/config.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/reflex/config.py b/reflex/config.py index 28d2e6a5f..52f589c8c 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -352,11 +352,14 @@ def get_config(reload: bool = False) -> Config: The app config. """ sys.path.insert(0, os.getcwd()) - try: - rxconfig = __import__(constants.Config.MODULE) - if reload: - importlib.reload(rxconfig) - return rxconfig.config - - except ImportError: - return Config(app_name="") # type: ignore + # only import the module if it exists. If a module spec exists then + # the module exists. + spec = importlib.util.find_spec(constants.Config.MODULE) # type: ignore + if not spec: + # we need this condition to ensure that a ModuleNotFound error is not thrown when + # running unit/integration tests. + return Config(app_name="") + rxconfig = importlib.import_module(constants.Config.MODULE) + if reload: + importlib.reload(rxconfig) + return rxconfig.config