Do not serialize the initial state when reflex db evaluates the pages
Found in the reflex 0.11.0a1 pre-release testing (FINDING-009).
All Submissions:
- Have you followed the guidelines stated in CONTRIBUTING.md file?
- Have you checked to ensure there aren't any other open Pull Requests for the desired changed?
Type of change
- Bug fix (non-breaking change which fixes an issue)
Changes To Core Features:
- Have you added an explanation of what your changes do and why you'd like us to include them?
- Have you written new tests for your core changes, as applicable?
- Have you successfully ran tests with your changes locally?
Description
On a fresh reflex-enterprise app (no .web), reflex db migrate exits 1 after the upgrade has already run, with ValueError: Library @radix-ui/themes is not bundled. On 0.10.1 it exited 0.
The trigger is the migrations.evaluate_pages() step that #7742 added to migrate. evaluate_pages ran get_compiled_app(dry_run=True) with skip-compile set. That branch of compile_app also serializes the initial state, and it never runs the compiler plugins' frontend-dependency bundling. So the bundled-library registry holds only the defaults, unless an earlier compile left one in .web. rxe's strict check in its lambda serializer then raises.
The db commands only need the pages evaluated, so that lazily imported models register. The fix:
App._compileandcompiler.compile_apptakecompile_initial_state: bool = True. Both skip-compile branches serialize the initial state only when it is True.migrations.evaluate_pages()callsapp._compile(dry_run=True, compile_initial_state=False).
Every other caller keeps the default, so backend-only starts, reflex compile --dry and the stateful-pages marker path behave as before. This also fixes reflex db init and makemigrations on such an app, which go through evaluate_pages too.
The pre-existing failure of a backend-only start on a fresh rxe checkout is out of scope (it also fails on 0.10.1). The skip branch could bundle the plugins' frontend dependencies before it serializes the state; that is a possible follow-up.
Tests
tests/units/utils/test_migrations.py::test_db_commands_do_not_serialize_the_initial_state: an app whose state holds a value with a strict serializer, which raises unless@radix-ui/themesis bundled, the way rxe's does. It runsreflex db init,makemigrationsandmigrate. Before the fix,initfails with the sameValueError; after the fix, all three exit 0.uv run pytest tests/units --covpasses (81.4% coverage;tests/units/reflex_bench/drivers/test_browser.pywas skipped because Chromium is not installed here).ruff check,ruff formatandpyright reflex testsare clean.
Generated by Claude Code