minor pydantic fixups
This commit is contained in:
parent
2def8b97e7
commit
c057f2e3f3
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from typing import Any, List, Type, Dict, Optional
|
from typing import Any, List, Type
|
||||||
|
|
||||||
import pydantic
|
import pydantic
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
@ -21,6 +21,8 @@ from typing import (
|
|||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from pydantic.fields import ModelPrivateAttr
|
||||||
|
|
||||||
from reflex.base import Base
|
from reflex.base import Base
|
||||||
from reflex.compiler.templates import STATEFUL_COMPONENT
|
from reflex.compiler.templates import STATEFUL_COMPONENT
|
||||||
from reflex.components.tags import Tag
|
from reflex.components.tags import Tag
|
||||||
@ -226,6 +228,8 @@ class Component(BaseComponent, ABC):
|
|||||||
inherited_rename_props = {}
|
inherited_rename_props = {}
|
||||||
for parent in reversed(cls.mro()):
|
for parent in reversed(cls.mro()):
|
||||||
if issubclass(parent, Component) and parent._rename_props:
|
if issubclass(parent, Component) and parent._rename_props:
|
||||||
|
if isinstance(parent._rename_props, ModelPrivateAttr):
|
||||||
|
parent._rename_props = parent._rename_props.default
|
||||||
inherited_rename_props.update(parent._rename_props)
|
inherited_rename_props.update(parent._rename_props)
|
||||||
cls._rename_props = inherited_rename_props
|
cls._rename_props = inherited_rename_props
|
||||||
|
|
||||||
|
@ -2080,6 +2080,7 @@ class StateManagerMemory(StateManager):
|
|||||||
class Config:
|
class Config:
|
||||||
"""The Pydantic config."""
|
"""The Pydantic config."""
|
||||||
|
|
||||||
|
# TODO: pydantic v2
|
||||||
fields = {
|
fields = {
|
||||||
"_states_locks": {"exclude": True},
|
"_states_locks": {"exclude": True},
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ from typing import (
|
|||||||
get_origin,
|
get_origin,
|
||||||
get_type_hints,
|
get_type_hints,
|
||||||
)
|
)
|
||||||
|
|
||||||
import pydantic_core
|
import pydantic_core
|
||||||
|
|
||||||
from reflex import constants
|
from reflex import constants
|
||||||
@ -248,8 +249,8 @@ def _decode_var(value: str) -> tuple[VarData | None, str]:
|
|||||||
def json_loads(s):
|
def json_loads(s):
|
||||||
try:
|
try:
|
||||||
return VarData.model_validate(s)
|
return VarData.model_validate(s)
|
||||||
except pydantic_core.ValidationError:
|
except pydantic_core.ValidationError as e:
|
||||||
raise ValueError(f"Invalid VarData: {s}")
|
raise ValueError(f"Invalid VarData: {s}") from e
|
||||||
# return VarData.model_validate(var_data_config.json_loads(f'"{s}"'))
|
# return VarData.model_validate(var_data_config.json_loads(f'"{s}"'))
|
||||||
|
|
||||||
# Compile regex for finding reflex var tags.
|
# Compile regex for finding reflex var tags.
|
||||||
|
Loading…
Reference in New Issue
Block a user