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#5710adhami3310 merged 2 commits intomainfrom
Conversation
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.
There was a problem hiding this comment.
Greptile Summary
This PR introduces a caching mechanism to optimize app name validation in Reflex applications. The change adds a _app_name_is_valid boolean field to the Config dataclass that tracks whether the app name has already been validated for the current process instance.
The implementation works by:
- Adding the
_app_name_is_validfield to theConfigclass (defaulting toFalse) - Modifying the
get_appfunction inprerequisites.pyto check this flag before calling_check_app_name - Setting the flag to
Trueafter successful validation in_check_app_name
This optimization addresses a specific developer experience issue where spurious "app.app module not found" errors would appear when deleting and replacing the main app module while the backend is running. The underlying problem was that _check_app_name performs filesystem operations to validate module existence, which could temporarily fail during file replacement operations in development workflows.
By caching the validation result on the Config instance (which persists for the backend process lifetime), the system eliminates redundant disk checks after initial successful validation. This maintains the same validation behavior on first access while improving performance and removing transient error messages during common development operations.
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it only optimizes an existing validation flow without changing core logic
- Score reflects the targeted nature of the fix and clear performance benefit, though the caching approach assumes Config instance stability
- Pay close attention to the interaction between the two modified files to ensure the flag is properly managed
2 files reviewed, 1 comment
CodSpeed Performance ReportMerging #5710 will not alter performanceComparing Summary
|
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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 founderrors that occur when deleting and replacing the main app module while the backend is running, but before triggering a reload.Repro code
Click on "Shuffle App Module" to simulate removing the app module and putting it back 2 seconds later. While the app module is shuffled, clicking on Backend or Frontend exception should NOT raise the module not found error. For the other ones, start the background task or the periodic onload, then click "Shuffle App Module", this should NOT raise the module not found error.
Without this fix, the above 3 scenarios cause an exception on the backend. (on_load path was fixed previously)