Skip to content

make pydantic optional - #6786

Open
benedikt-bartscher wants to merge 6 commits into
reflex-dev:mainfrom
benedikt-bartscher:make-pydantic-optional
Open

make pydantic optional#6786
benedikt-bartscher wants to merge 6 commits into
reflex-dev:mainfrom
benedikt-bartscher:make-pydantic-optional

Conversation

@benedikt-bartscher

Copy link
Copy Markdown
Contributor

No description provided.

@codspeed-hq

codspeed-hq Bot commented Jul 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 26 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing benedikt-bartscher:make-pydantic-optional (e7d2ae2) with main (7e365ce)2

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

  2. No successful run was found on main (69ef304) during the generation of this report, so 7e365ce was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes pydantic an optional dependency for both reflex and reflex-base, removing it from hard install requirements. Users who need pydantic model support can opt in via reflex[pydantic] or continue using reflex[db].

  • packages/reflex-base/pyproject.toml: pydantic moved from dependencies to [project.optional-dependencies] under the key pydantic.
  • pyproject.toml: adds pydantic = ["reflex-base[pydantic]"] extra for the root reflex package; the db extra retains pydantic directly for backwards compatibility.
  • tests/units/test_optional_pydantic.py: new subprocess-based test that blocks pydantic/sqlmodel/alembic/sqlalchemy via sys.meta_path wrappers and sys.modules purge, then asserts state creation, component rendering, and datetime serializers all function correctly without those packages.

Confidence Score: 5/5

Safe to merge. The packaging change is a clean extraction of pydantic into an optional extra; the db extra retains pydantic directly so existing users of reflex[db] are unaffected.

The change is isolated to dependency declarations and a new test file. The subprocess-based test correctly isolates the without-pydantic path using both meta_path wrapping and sys.modules purge, matching the concerns from the existing review thread. No runtime logic is altered in this PR.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
packages/reflex-base/pyproject.toml Removes pydantic from hard deps; adds it as optional-dep pydantic = ["pydantic >=2.12.0,<3.0"].
pyproject.toml Adds pydantic = ["reflex-base[pydantic]"] optional extra to the root reflex package; db extra keeps pydantic directly for backwards compatibility.
tests/units/test_optional_pydantic.py New test that spawns a subprocess with pydantic/sqlmodel/alembic/sqlalchemy blocked via meta_path wrappers and sys.modules purge, then verifies state, component render, and serializers all work without those packages present.
news/+pydantic-optional.breaking.md Changelog entry describing the breaking change; mentions the new reflex[pydantic] and reflex[db] install paths.
packages/reflex-base/news/+pydantic-optional.breaking.md Changelog entry for reflex-base describing pydantic as no longer a hard dependency.

Reviews (6): Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." | Re-trigger Greptile

Comment thread tests/units/test_optional_pydantic.py

@masenf masenf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting; i thought we had pydantic as optional for some time now, but i guess not...

@benedikt-bartscher
benedikt-bartscher marked this pull request as ready for review July 17, 2026 16:35
@benedikt-bartscher
benedikt-bartscher requested a review from a team as a code owner July 17, 2026 16:35
@benedikt-bartscher

Copy link
Copy Markdown
Contributor Author

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants