migrate pydantic config classes to ConfigDict
This commit is contained in:
parent
b3593537be
commit
0240541d0b
@ -50,12 +50,12 @@ class Base(pydantic.BaseModel):
|
||||
frontend and backend should subclass this class.
|
||||
"""
|
||||
|
||||
class Config:
|
||||
"""Pydantic config."""
|
||||
|
||||
arbitrary_types_allowed = True
|
||||
use_enum_values = True
|
||||
extra = "allow"
|
||||
# Pydantic config
|
||||
model_config = pydantic.ConfigDict(
|
||||
arbitrary_types_allowed=True,
|
||||
use_enum_values=True,
|
||||
extra="allow",
|
||||
)
|
||||
|
||||
def json(self) -> str:
|
||||
"""Convert the object to a json string.
|
||||
|
@ -127,10 +127,10 @@ class DBConfig(Base):
|
||||
class Config(Base):
|
||||
"""A Reflex config."""
|
||||
|
||||
class Config:
|
||||
"""Pydantic config for the config."""
|
||||
|
||||
validate_assignment = True
|
||||
# Pydantic config
|
||||
model_config = pydantic.ConfigDict(
|
||||
validate_assignment=True,
|
||||
)
|
||||
|
||||
# The name of the app.
|
||||
app_name: str
|
||||
|
@ -16,6 +16,8 @@ from typing import (
|
||||
Union,
|
||||
)
|
||||
|
||||
from pydantic import ConfigDict
|
||||
|
||||
from reflex import constants
|
||||
from reflex.base import Base
|
||||
from reflex.utils import console, format
|
||||
@ -147,11 +149,10 @@ class EventHandler(EventActionsMixin):
|
||||
# The function to call in response to the event.
|
||||
fn: Any
|
||||
|
||||
class Config:
|
||||
"""The Pydantic config."""
|
||||
|
||||
# Needed to allow serialization of Callable.
|
||||
frozen = True
|
||||
# Pydantic config
|
||||
model_config = ConfigDict(
|
||||
frozen=True, # Needed to allow serialization of Callable.
|
||||
)
|
||||
|
||||
@property
|
||||
def is_background(self) -> bool:
|
||||
@ -219,11 +220,10 @@ class EventSpec(EventActionsMixin):
|
||||
# TODO: pydantic v2 add rx.Var type annotation?
|
||||
args: Tuple[Tuple[Any, Any], ...] = ()
|
||||
|
||||
class Config:
|
||||
"""The Pydantic config."""
|
||||
|
||||
# Required to allow tuple fields.
|
||||
frozen = True
|
||||
# Pydantic config
|
||||
model_config = ConfigDict(
|
||||
frozen=True, # Required to allow tuple fields.
|
||||
)
|
||||
|
||||
def with_args(self, args: Tuple[Tuple[Var, Var], ...]) -> EventSpec:
|
||||
"""Copy the event spec, with updated args.
|
||||
|
@ -62,8 +62,7 @@ class Model(Base, sqlmodel.SQLModel):
|
||||
non_default_primary_key_fields = [
|
||||
field_name
|
||||
for field_name, field in cls.model_fields.items()
|
||||
if field_name != "id"
|
||||
and getattr(field, "primary_key", None) is True
|
||||
if field_name != "id" and getattr(field, "primary_key", None) is True
|
||||
]
|
||||
if non_default_primary_key_fields:
|
||||
cls.model_fields.pop("id", None)
|
||||
|
@ -2104,17 +2104,19 @@ class StateManagerMemory(StateManager):
|
||||
# The dict of mutexes for each client
|
||||
_states_locks: Dict[str, asyncio.Lock] = pydantic.PrivateAttr({})
|
||||
|
||||
class Config:
|
||||
"""The Pydantic config."""
|
||||
|
||||
# TODO: pydantic v2
|
||||
fields = {
|
||||
"_states_locks": {"exclude": True},
|
||||
}
|
||||
|
||||
# Pydantic config
|
||||
model_config = pydantic.ConfigDict(
|
||||
arbitrary_types_allowed=True,
|
||||
use_enum_values=True,
|
||||
extra="allow",
|
||||
# json_encoders = {
|
||||
# MutableProxy: lambda v: v.__wrapped__,
|
||||
# MutableProxy: lambda v: v.__wrapped__, # this is currently done in _get_value
|
||||
# }
|
||||
# TODO: pydantic v2
|
||||
# fields = {
|
||||
# "_states_locks": {"exclude": True},
|
||||
# }
|
||||
)
|
||||
|
||||
async def get_state(self, token: str) -> BaseState:
|
||||
"""Get the state for a token.
|
||||
|
Loading…
Reference in New Issue
Block a user