Skip to content

Commit 948b993

Browse files
ENG-7314: Only check for valid app name once per config instance (#5710)
* ENG-7314: Only check for valid app name once per config instance After the backend comes up, we check the app name once and validate that it's good. There is no need to check it again in the same process. Fixes the spurious `app.app module not found` errors that occur when deleting and replacing the main app module while the backend is running, but before triggering a reload. * Update reflex/config.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent 38e1efc commit 948b993

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

reflex/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ class Config(BaseConfig):
284284
See the [configuration](https://reflex.dev/docs/getting-started/configuration/) docs for more info.
285285
"""
286286

287+
# Track whether the app name has already been validated for this Config instance.
288+
_app_name_is_valid: bool = dataclasses.field(default=False, repr=False)
289+
287290
def _post_init(self, **kwargs):
288291
"""Post-initialization method to set up the config.
289292

reflex/utils/prerequisites.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def _check_app_name(config: Config):
165165
else:
166166
msg += f"Ensure app_name='{config.app_name}' in rxconfig.py matches your folder structure."
167167
raise ModuleNotFoundError(msg)
168+
config._app_name_is_valid = True
168169

169170

170171
def get_app(reload: bool = False) -> ModuleType:
@@ -184,7 +185,9 @@ def get_app(reload: bool = False) -> ModuleType:
184185
try:
185186
config = get_config()
186187

187-
_check_app_name(config)
188+
# Avoid hitting disk when the app name has already been validated in this process.
189+
if not config._app_name_is_valid:
190+
_check_app_name(config)
188191

189192
module = config.module
190193
sys.path.insert(0, str(Path.cwd()))

0 commit comments

Comments
 (0)