Skip to content

Rewrite the database docs around SQLAlchemy models - #7679

Open
FarhanAliRaza wants to merge 6 commits into
mainfrom
ccr-921eda66-kjt8mt-model-deprecation
Open

FarhanAliRaza wants to merge 6 commits into
mainfrom
ccr-921eda66-kjt8mt-model-deprecation

Conversation

@FarhanAliRaza

@FarhanAliRaza FarhanAliRaza commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Type of change

  • This change requires a documentation update

Description

The database overview, tables, queries and relationships pages and the rx.table database examples still taught the deprecated rx.Model and rx.session. Rather than adding deprecation callouts, this rewrites them around the supported pattern:

  • One shared base, 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) and Session = sessionmaker(engine, expire_on_commit=False), opened per event handler.
  • 2.0-style queries: session.scalars(select(User)), session.scalar(...), session.get(...), plus the async equivalents with async_sessionmaker.
  • rx.ModelRegistry.register(Base) so reflex db init / makemigrations / migrate keep managing the schema. Verified end to end against a scratch app.
  • Relationships: ForeignKey + relationship(..., repr=False), eager loading with selectinload, and a loaded-attributes @rx.serializer for the base so linked objects serialize without lazy loads on detached instances.
  • The overview gains a "Migrating existing apps" table mapping each rx.Model construct 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 use dataclasses.

Testing

docs/app/tests/test_database_examples.py extracts 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.Model usages 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

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
@FarhanAliRaza
FarhanAliRaza requested review from a team and Alek99 as code owners October 27, 2026 20:17
@FarhanAliRaza FarhanAliRaza added the documentation Improvements or additions to documentation label Oct 27, 2026 — with Claude

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

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

Comment thread docs/database/tables.md Outdated
@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The latest changes appear safe to merge; no new actionable issue was found.

Summary

Rewrites the database guides and table examples around SQLAlchemy models, session factories, and select queries.

  • Database apps now get one SQLAlchemy setup for tables and migrations.
  • Database handlers now use SQLAlchemy 2.0 queries for sync and async work.
  • Linked rows load and serialize only what the page needs.
  • Table examples now query and export SQLAlchemy customer rows.

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

Comment thread docs/database/queries.md Outdated
Only rx.Model emits the deprecation warning; rx.session has no removal
date of its own.

Claude-Session: https://claude.ai/code/session_01LwJUCUDZhZY71q8Azr37BQ
@codspeed

codspeed Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 21 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 148 untouched benchmarks


Comparing ccr-921eda66-kjt8mt-model-deprecation (2551222) with main (17370c2)

Open in CodSpeed

@linear-code

linear-code Bot commented Oct 27, 2026

Copy link
Copy Markdown

ENG-13589

Copy link
Copy Markdown
Contributor Author

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:

Database tables page

Expanded 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
@FarhanAliRaza FarhanAliRaza changed the title Note the rx.Model deprecation on every docs page that still uses it Rewrite the database docs around SQLAlchemy models Oct 27, 2026
Comment thread docs/database/queries.md
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

@cubic-dev-ai cubic-dev-ai Bot left a comment •

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.

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

Comment thread docs/database/tables.md Outdated
Comment thread docs/app/tests/test_database_examples.py
Comment thread docs/database/queries.md Outdated
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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant