-
Notifications
You must be signed in to change notification settings - Fork 1.7k
make pydantic optional #6786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benedikt-bartscher
wants to merge
4
commits into
reflex-dev:main
Choose a base branch
from
benedikt-bartscher:make-pydantic-optional
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+91
−4
Open
make pydantic optional #6786
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| `pip install reflex` no longer installs `pydantic`; pydantic model support activates when it is installed. Use the new `reflex[pydantic]` extra (or `reflex[db]`) to keep it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| `pydantic` is no longer a hard dependency; pydantic model support activates when it is installed. Use the `reflex-base[pydantic]` extra (or `reflex[db]`) to keep it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| """Verify reflex imports and works when pydantic is not installed.""" | ||
|
|
||
| import subprocess | ||
| import sys | ||
|
|
||
| # Runs in a subprocess with pydantic (and the db extras that require it) | ||
| # blocked, mirroring the "without db dependencies" CI job. | ||
| _SCRIPT = """ | ||
| import sys | ||
|
|
||
| BLOCKED = ("pydantic", "sqlmodel", "alembic", "sqlalchemy") | ||
|
|
||
|
|
||
| class _Filter: | ||
| # Hide blocked packages from every finder so both ``import`` and | ||
| # ``find_spec`` see them as absent. | ||
| def __init__(self, inner): | ||
| self.inner = inner | ||
|
|
||
| def find_spec(self, name, path=None, target=None): | ||
| if name.partition(".")[0] in BLOCKED: | ||
| return None | ||
| finder = getattr(self.inner, "find_spec", None) | ||
| return finder(name, path, target) if finder is not None else None | ||
|
|
||
|
|
||
| sys.meta_path = [_Filter(f) for f in sys.meta_path] | ||
|
|
||
| # find_spec consults sys.modules before meta_path — purge anything a .pth or | ||
| # startup hook may have imported eagerly. | ||
| for mod in [m for m in sys.modules if m.partition(".")[0] in BLOCKED]: | ||
| del sys.modules[mod] | ||
|
|
||
| from importlib.util import find_spec | ||
|
|
||
| assert find_spec("pydantic") is None | ||
|
|
||
| import datetime | ||
|
|
||
| import reflex as rx | ||
| from reflex_base.utils import serializers | ||
|
|
||
|
|
||
| class S(rx.State): | ||
| val: rx.Field[str] = rx.field("hello") | ||
|
|
||
|
|
||
| comp = rx.text(S.val) | ||
| assert "val" in str(comp.render()) | ||
|
|
||
| assert serializers.serialize(datetime.datetime(2026, 1, 2, 3, 4, 5)) == "2026-01-02 03:04:05" | ||
| assert not any( | ||
| getattr(cls, "__module__", "").startswith("pydantic") | ||
| for cls in serializers.SERIALIZERS | ||
| ) | ||
|
|
||
| print("OK") | ||
| """ | ||
|
|
||
|
|
||
| def test_reflex_works_without_pydantic() -> None: | ||
| """Core import, state, component render, and serializers work without pydantic.""" | ||
| result = subprocess.run( | ||
| [sys.executable, "-c", _SCRIPT], | ||
| capture_output=True, | ||
| text=True, | ||
| timeout=120, | ||
| check=False, | ||
| ) | ||
| assert result.returncode == 0, ( | ||
| f"reflex failed without pydantic:\nstdout: {result.stdout}\nstderr: {result.stderr}" | ||
| ) | ||
| assert "OK" in result.stdout | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.