Repository navigation
Do not serialize the initial state when reflex db evaluates the pages - #7817
Conversation
`reflex db init`, `makemigrations` and `migrate` evaluate every page so that lazily imported models are registered. They did so through a dry-run, skip-compile `get_compiled_app`, which also serialized the initial state. Without a frontend compile, the libraries that compiler plugins bundle are not registered, so a serializer that requires one (reflex-enterprise's strict bundled-library check) failed a fresh `reflex db migrate` with "Library @radix-ui/themes is not bundled", after the upgrade had run. `App._compile` and `compile_app` take `compile_initial_state` (default True, so every other caller is unchanged); `evaluate_pages` passes False. Found in the reflex 0.11.0a1 pre-release testing (FINDING-009). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
There was a problem hiding this comment.
All reported issues were addressed across 5 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
[Medium impact] The PR appears safe to merge. SummaryDatabase commands evaluate pages without serializing the initial state.
Reviews (3) · Last reviewed commit: "Make the db-commands test independent of..." · Reviewed by Greptile |
…e serializers The test serializer now raises whenever it is called, so the test does not pass merely because an earlier test bundled @radix-ui/themes, and the test restores the global serializer registries it extends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
Merging this PR will degrade performance by 4.33%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
|
On the CodSpeed report: Generated by Claude Code |
…#7817) * Do not serialize the initial state when reflex db evaluates the pages `reflex db init`, `makemigrations` and `migrate` evaluate every page so that lazily imported models are registered. They did so through a dry-run, skip-compile `get_compiled_app`, which also serialized the initial state. Without a frontend compile, the libraries that compiler plugins bundle are not registered, so a serializer that requires one (reflex-enterprise's strict bundled-library check) failed a fresh `reflex db migrate` with "Library @radix-ui/themes is not bundled", after the upgrade had run. `App._compile` and `compile_app` take `compile_initial_state` (default True, so every other caller is unchanged); `evaluate_pages` passes False. Found in the reflex 0.11.0a1 pre-release testing (FINDING-009). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi * Make the db-commands test independent of bundled libraries and restore serializers The test serializer now raises whenever it is called, so the test does not pass merely because an earlier test bundled @radix-ui/themes, and the test restores the global serializer registries it extends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi --------- Co-authored-by: Claude <noreply@anthropic.com> (cherry picked from commit 81a08eb)
…the train Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dxjadq3qkhKnqZR2b9WBFi
Found in the reflex 0.11.0a1 pre-release testing (FINDING-009).
All Submissions:
Type of change
Changes To Core Features:
Description
On a fresh reflex-enterprise app (no
.web),reflex db migrateexits 1 after the upgrade has already run, withValueError: 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 tomigrate.evaluate_pagesranget_compiled_app(dry_run=True)with skip-compile set. That branch ofcompile_appalso 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 --dryand the stateful-pages marker path behave as before. This also fixesreflex db initandmakemigrationson such an app, which go throughevaluate_pagestoo.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