avoid validating app when running in backend only#6203
avoid validating app when running in backend only#6203adhami3310 wants to merge 1 commit intomainfrom
Conversation
Greptile SummaryThis PR modifies the Key changes:
Confidence Score: 3/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[_run called] --> B{frontend enabled?}
B -- Yes --> C[compile_or_validate_app\ncompile=frontend\ncheck_if_schema_up_to_date=True]
C --> D{should_use_granian?}
D -- Yes --> E[ProcessPoolExecutor.submit]
D -- No --> F[call directly]
E --> G{return_result?}
F --> G
G -- False --> H[SystemExit 1]
G -- True --> I[Continue startup]
B -- No\nbackend-only --> J[⚠️ Skip validation\nAND schema check]
J --> I
Last reviewed commit: "avoid validating app..." |
| if frontend: | ||
| # Get the app module. | ||
| app_task = prerequisites.compile_or_validate_app | ||
| args = (frontend,) | ||
| kwargs = { | ||
| "check_if_schema_up_to_date": True, | ||
| "prerender_routes": exec.should_prerender_routes(), | ||
| } | ||
|
|
||
| # Granian fails if the app is already imported. | ||
| if should_use_granian(): | ||
| import concurrent.futures | ||
|
|
||
| compile_future = concurrent.futures.ProcessPoolExecutor(max_workers=1).submit( | ||
| app_task, | ||
| *args, | ||
| **kwargs, | ||
| ) | ||
| return_result = compile_future.result() | ||
| else: | ||
| return_result = app_task(*args, **kwargs) | ||
|
|
||
| if not return_result: | ||
| raise SystemExit(1) | ||
| if not return_result: | ||
| raise SystemExit(1) |
There was a problem hiding this comment.
Schema validation silently skipped in backend-only mode
Previously, even when frontend=False (backend-only mode), compile_or_validate_app(compile=False, check_if_schema_up_to_date=True, ...) was still called. This invoked get_and_validate_app(check_if_schema_up_to_date=True), which checks whether database migrations are up-to-date before the server starts.
By wrapping the entire block in if frontend:, the schema-currency check is now silently skipped when running backend-only. Since the backend is responsible for all database operations, this check is arguably more important in backend-only deployments than in full-stack ones. If migrations are out of date, errors will surface as confusing runtime failures rather than a clear startup-time warning.
Consider either:
- Retaining the schema check for the backend-only path, e.g.:
if frontend:
# compile/validate + schema check (existing block)
...
elif backend:
# still validate schema even without frontend
from reflex.utils import prerequisites
if not prerequisites.compile_or_validate_app(
compile=False,
check_if_schema_up_to_date=True,
):
raise SystemExit(1)- Or explicitly documenting (with a comment) that the schema check is intentionally omitted in backend-only mode and explaining why that is safe.
No description provided.