Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions reflex/reflex.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,29 +211,32 @@ def _run(

prerequisites.check_latest_package_version(constants.Reflex.MODULE_NAME)

# 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 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)
Comment on lines +214 to +239
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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:

  1. 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)
  1. Or explicitly documenting (with a comment) that the schema check is intentionally omitted in backend-only mode and explaining why that is safe.


if env != constants.Env.PROD and env != constants.Env.DEV:
msg = f"Invalid env: {env}. Must be DEV or PROD."
Expand Down
Loading