make pydantic optional - #6786
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Greptile SummaryThis PR makes pydantic an optional dependency of both
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| packages/reflex-base/src/reflex_base/event/processor/base_state_processor.py | Moves the pydantic find_spec check from per-event to module-import time, setting BaseModelV2 = None when pydantic is absent; hot-path guard is correct and well-commented. |
| packages/reflex-base/pyproject.toml | Moves pydantic from hard dependency to [project.optional-dependencies]; version constraint preserved. |
| pyproject.toml | Adds pydantic = ["reflex-base[pydantic]"] extra; db extra keeps pydantic as a direct dependency. |
| tests/units/test_optional_pydantic.py | New subprocess-based test that blocks pydantic via sys.meta_path filter + sys.modules purge, verifying core reflex functionality works without pydantic; well-structured isolation mechanism. |
| news/+pydantic-optional.breaking.md | Breaking change note documenting the removal of pydantic as a hard dependency and the new reflex[pydantic] extra. |
| uv.lock | Lockfile updated to reflect pydantic becoming optional; also includes an aiohttp version downgrade from 3.14.3 to 3.14.1. |
Reviews (8): Last reviewed commit: "Resolve pydantic presence once instead o..." | Re-trigger Greptile
masenf
left a comment
There was a problem hiding this comment.
interesting; i thought we had pydantic as optional for some time now, but i guess not...
I remember reading some git commits or changelogs which mentioned this as well - however somehow it currently isn't optional. I guess this is ready for review now. |
With pydantic optional, find_spec("pydantic") in _transform_event_arg
does a full sys.path scan on every dict-payload argument when pydantic
is absent (measured 85us per call; 0.64us after hoisting). Bind the
BaseModel reference once at import, like the other guarded sites.
|
Validated this end to end in a real app: installed the branch's packages into a clean venv (confirmed nothing pulls pydantic transitively — 40 packages, no pydantic), ran a counter app, and exercised state events in the browser — compile, hydration, and event round-trips all work without pydantic. Also confirmed the One perf issue surfaced and is fixed in 02f7152: |
pydantic_optional (#6786): bare/pydantic/db extras and the in-place upgrade path all verified end-to-end in the browser; no regressions vs 0.9.8. Two low-severity error-message papercuts recorded. typing_python (#6944/#6890/#6846): PEP 695 aliases compile and render on 3.11-3.14, and Python 3.14 builtin-annotation handling passes fully. Found: runtime assignment to an alias-annotated state var raises TypeError in State.__setattr__ (high — mutating handlers die), and an uncalled handler with an alias-annotated arg crashes page compile. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EMjBXPozsNeQNSBZecNH8x
A ~29s 1920x1080 motion graphic covering the end-user-facing changes in 0.9.9, sourced from the 0.9.9a1 and 0.9.9a2 changelog entries across reflex, reflex-base, the component packages and reflex-hosting-cli. Nine beats: the dev-mode main-thread win (#6905), call-site auto-memoization of @rx.memo (#6949), the move to React Router 8 (#6854), DevTools component naming (#6945), stdlib logging with --json plus the client_error report (#6863, #6865, #6827), the cloud CLI's whoami/token and autoscaling flags (#6918, #6884, #6948), and a grid of the smaller fixes a user would notice (#6786, #6593, #6944, #6971, #6790, #6920). Styled to match reflex.dev by reusing its design system rather than approximating it: the dark violet/slate scales, wave-line motif, radial bloom and type scale come from reflex-site-shared, and the fonts are the same @fontsource-variable Instrument Sans and JetBrains Mono files the site serves. Source only — the rendered mp4 is a build artifact, regenerated by `npm run build` and ignored. Lives outside the packaged tree (hatch only includes /reflex), so it does not affect the published wheel or sdist. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016arkVKmoogzUtZNfZZSvSo
No description provided.