Skip to content

make pydantic optional - #6786

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

make pydantic optional#6786
benedikt-bartscher wants to merge 5 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 (c95cebc) with main (d932ee8)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 (02f442b) during the generation of this report, so d932ee8 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 by moving it from core dependencies to a [pydantic] optional extra in each package. Users who rely on pydantic model support can opt in via pip install reflex[pydantic] (or continue using reflex[db] which still pins pydantic directly).

  • reflex-base/pyproject.toml removes the hard pydantic dep and adds [project.optional-dependencies] pydantic = ["pydantic >=2.12.0,<3.0"].
  • pyproject.toml adds pydantic = ["reflex-base[pydantic]"] as an extra; the existing db extra retains its direct pydantic pin.
  • A new subprocess-based test installs a meta-path filter and purges sys.modules to simulate "no pydantic" and asserts that state, components, and serializers all function correctly.
  • uv.lock is updated to reflect the new optional-dependency graph.

Confidence Score: 5/5

Safe to merge — the change is additive, existing users of reflex[db] are unaffected, and the new test verifies core functionality without pydantic.

The change is mechanical (moving a dep to an extra) and well-tested. No behavioural logic is altered; the only coupling risk is the duplicate pydantic version pin between the db extra and reflex-base[pydantic], which is a maintenance nit rather than a defect.

Files Needing Attention: No files require special attention beyond the duplicate pydantic version pin in pyproject.toml.

Important Files Changed

Filename Overview
pyproject.toml Adds pydantic optional-dependencies entry that delegates to reflex-base[pydantic]; the db extra retains a direct pydantic pin which duplicates the version constraint.
packages/reflex-base/pyproject.toml Removes pydantic from core dependencies and adds it as an optional [pydantic] extra; straightforward and correct.
tests/units/test_optional_pydantic.py New subprocess-based test that blocks pydantic via meta_path filter and sys.modules purge, then verifies core reflex import/state/component/serializer functionality still works.
uv.lock Lockfile updated to reflect the new optional pydantic extras for both reflex and reflex-base; mechanically correct.
news/+pydantic-optional.breaking.md Changelog entry documenting the breaking change for the reflex package.
packages/reflex-base/news/+pydantic-optional.breaking.md Changelog entry documenting the breaking change for the reflex-base package.

Reviews (5): 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