Repository navigation
Rewrite the database docs around SQLAlchemy models - #7679
FarhanAliRaza wants to merge 6 commits into
Conversation
The database overview already warns that rx.Model is deprecated since 0.9.2, but the tables, queries and relationships pages and the rx.table database example presented it without any note. Claude-Session: https://claude.ai/code/session_01LwJUCUDZhZY71q8Azr37BQ
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
[Low impact] The latest changes appear safe to merge; no new actionable issue was found. SummaryRewrites the database guides and table examples around SQLAlchemy models, session factories, and
Both supplied previous threads are unnumbered, so neither receives a numbered finding entry. The migration examples now register their bases. The removal-date thread was manually resolved by FarhanAliRaza after their reply stated that the notices were removed. Reviews (5) · Last reviewed commit: "Address review on the database docs rewr..." · Reviewed by Greptile |
Only rx.Model emits the deprecation warning; rx.session has no removal date of its own. Claude-Session: https://claude.ai/code/session_01LwJUCUDZhZY71q8Azr37BQ
Merging this PR will not alter performance1 warning
Comparing |
|
Validated in the docs app running locally on this branch. The callout renders collapsed at the top of the database tables page and expands to the deprecation note: Generated by Claude Code |
The database overview, tables, queries and relationships pages and the table component's database examples documented the deprecated rx.Model and rx.session. Instead of flagging that with a deprecation callout, show the supported pattern: a shared MappedAsDataclass + DeclarativeBase base (so Reflex serializes rows into state without extra code), a sessionmaker factory with expire_on_commit=False, 2.0-style select() queries, and rx.ModelRegistry.register(Base) so the reflex db migration commands keep working. The overview gains a migration table from rx.Model, and the relationships page explains eager loading and a loaded-attributes serializer for models with relationships. The table page's CSV and JSON download examples relied on the Pydantic __fields__ and .dict() APIs; they now use dataclasses. A new docs test executes the documented models, handlers and serializers against a SQLite file, and reflex db init/makemigrations/migrate were verified against a registered DeclarativeBase. Claude-Session: https://claude.ai/code/session_01LwJUCUDZhZY71q8Azr37BQ
The queries, relationships and table pages define their own Base for self-contained examples; register each one the same way the overview and tables pages do, so copying any page gives migrations that create its tables. Claude-Session: https://claude.ai/code/session_01LwJUCUDZhZY71q8Azr37BQ
There was a problem hiding this comment.
All reported issues were addressed across 8 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Describe session.scalar() as returning the first column of the first row, guard the serializer example against a row that has not been inserted yet, and keep the docs example test from leaking serializers into the process-wide registry. Claude-Session: https://claude.ai/code/session_01LwJUCUDZhZY71q8Azr37BQ


Type of change
Description
The database overview, tables, queries and relationships pages and the
rx.tabledatabase examples still taught the deprecatedrx.Modelandrx.session. Rather than adding deprecation callouts, this rewrites them around the supported pattern:class Base(MappedAsDataclass, DeclarativeBase). The dataclass mapping gives models a keyword constructor and lets Reflex serialize rows into state with no extra code.engine = create_engine(rx.config.get_config().db_url)andSession = sessionmaker(engine, expire_on_commit=False), opened per event handler.session.scalars(select(User)),session.scalar(...),session.get(...), plus the async equivalents withasync_sessionmaker.rx.ModelRegistry.register(Base)soreflex db init/makemigrations/migratekeep managing the schema. Verified end to end against a scratch app.ForeignKey+relationship(..., repr=False), eager loading withselectinload, and a loaded-attributes@rx.serializerfor the base so linked objects serialize without lazy loads on detached instances.rx.Modelconstruct to its replacement. The SQLModel datetime upgrade note stays on the tables page under its existing anchor.Also fixed along the way: the table page's CSV and JSON download examples used the Pydantic-only
Customer.__fields__and.dict(), which do not exist on these models. They now usedataclasses.Testing
docs/app/tests/test_database_examples.pyextracts the documented models, handlers and serializers from the pages and executes them against a SQLite file (CRUD, aggregates, raw SQL, relationships with eager loading, table load/filter/sort/paginate/download). The full docs suite passes.Not touched here: the
rx.Modelusages on the dialog, alert dialog, enterprise AG Grid and code structure pages, which are outside the database section.https://claude.ai/code/session_01LwJUCUDZhZY71q8Azr37BQ
Generated by Claude Code