Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address an issue with pydantic v2 models as Vars (#3396)
* Addresses an issue with pydantic v2 models as Vars It looks like there's an issue with state vars which are pydantic v2 models... Here's a reproducible test case: ```python import reflex as rx from pydantic import BaseModel from reflex.utils.serializers import serializer class User(BaseModel): has_image: bool = False @Serializer def serialize_user(user: User) -> dict: return user.dict() class State(rx.State): user: User = None def index() -> rx.Component: return rx.container( rx.cond(State.user, rx.text(State.user.has_image), rx.text("No user")) ) app = rx.App() app.add_page(index) ``` This app works only with pydantic <2 installed: ```bash reflex-test $ reflex run ... AttributeError: 'FieldInfo' object has no attribute 'outer_type_' reflex-test $ pip install pydantic==1.10.15 βββββββββββββββββββββββββββββββββββ Starting Reflex App βββββββββββββββββββββββββββββββββββ Compiling: ββββββββββββββββββββββββββββββββββββββββ 100% 13/13 0:00:00 βββββββββββββββββββββββββββββββββββββββ App Running βββββββββββββββββββββββββββββββββββββββ App running at: http://localhost:3000 ``` Looks like this is caused by `outer_type_` no [longer existing][1] in pydantic v2. I'm guessing this was introduced back in [v0.4.6][2]. 1: pydantic/pydantic#7217 2: 86526cb This change explicitly ignores pydantic v2 models in `get_attribute_access_type`, rather than trying to treat them as v1 models. * ruff formatting --------- Co-authored-by: Masen Furer <m_github@0x26.net>
- Loading branch information