reflex/reflex
Elliot Kroo 168501d58a
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: https://github.com/pydantic/pydantic/discussions/7217
2: 86526cba51

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>
2024-06-07 09:47:54 -07:00
..
.templates Radix Themes + Tailwind Harmony (#3355) 2024-05-28 12:21:28 -07:00
compiler [REF-3004] Use relative path to stylesheet for postcss-import compat (#3435) 2024-06-05 10:02:05 -07:00
components Recharts supporting radix color, add event triggers (#3430) 2024-06-07 09:47:12 -07:00
constants [REF-2956] Fail When Backend port or frontend port is explicitly provided and the port is in use (#3432) 2024-06-05 11:46:00 -07:00
custom_components Use twine environment variables if set (#3353) 2024-05-21 14:43:49 -07:00
experimental promote toast to main namespace (#3422) 2024-06-06 10:38:35 -07:00
middleware feat: Synchronizing localStorage between tabs using browser events (#2533) 2024-02-20 15:14:55 -08:00
utils Address an issue with pydantic v2 models as Vars (#3396) 2024-06-07 09:47:54 -07:00
__init__.py promote toast to main namespace (#3422) 2024-06-06 10:38:35 -07:00
__init__.pyi promote toast to main namespace (#3422) 2024-06-06 10:38:35 -07:00
__main__.py add __main__ entry point to allow python -m reflex (#1516) 2023-08-03 14:26:50 -07:00
admin.py Allow view overrides for registering models with admin (#1249) 2023-06-27 14:08:09 -07:00
app_module_for_backend.py Catch more errors in frontend/backend (#3346) 2024-05-20 16:55:41 -07:00
app.py [REF-2821]Improve Dynamic Imports (#3345) 2024-05-31 16:43:10 +00:00
base.py [REF-2774] Add ReflexError and subclasses, send in telemetry (#3271) 2024-05-10 12:12:42 -07:00
config.py [bug] Avoid deleting endpoint port when running on Replit (#3447) 2024-06-06 14:00:00 -07:00
event.py promote toast to main namespace (#3422) 2024-06-06 10:38:35 -07:00
model.py [REF-2764] dep update 0.5.0 (#3245) 2024-05-07 15:15:52 -07:00
page.py separate DECORATED_PAGES per reflex app (#3102) 2024-04-22 11:32:31 -07:00
reflex.py [REF-2956] Fail When Backend port or frontend port is explicitly provided and the port is in use (#3432) 2024-06-05 11:46:00 -07:00
route.py [REF-2643] Throw Errors for duplicate Routes (#3155) 2024-05-03 12:15:40 -07:00
state.py [REF-1356] Track changes applied to Base subclass via helper method. (#2242) 2024-05-31 14:58:58 -07:00
style.py [REF-2878] Map fontFamily to fontFamily and --default-font-family (#3380) 2024-05-23 15:54:39 -07:00
testing.py Webdriver ArgOptions improvements (#3429) 2024-06-06 13:59:41 -07:00
vars.py [REF-3010] Circular Imports Fix (#3433) 2024-06-04 11:50:02 -07:00
vars.pyi Explicit deps and interval for computed vars (#3231) 2024-05-28 12:27:27 -07:00