Skip to content
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

Replace some invalid imports #637

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions sqlmodel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@
cast,
)

from fastapi._compat import ModelField, UndefinedType
from jinja2 import Undefined
from pydantic import BaseConfig, BaseModel
from pydantic.errors import ConfigError, DictError
from pydantic.fields import SHAPE_SINGLETON
from pydantic.fields import FieldInfo as PydanticFieldInfo
from pydantic.fields import ModelField, Undefined, UndefinedType
from pydantic.main import ModelMetaclass, validate_model
from pydantic.typing import NoArgAnyCallable, resolve_annotations
from pydantic.utils import ROOT_KEY, Representation
from pydantic.v1.fields import SHAPE_SINGLETON
from sqlalchemy import Boolean, Column, Date, DateTime
from sqlalchemy import Enum as sa_Enum
from sqlalchemy import Float, ForeignKey, Integer, Interval, Numeric, inspect
Expand Down Expand Up @@ -573,7 +574,7 @@ def parse_obj(
if update is not None:
obj = {**obj, **update}
# End SQLModel support dict
return super().parse_obj(obj)
return super().model_validate(obj)

def __repr_args__(self) -> Sequence[Tuple[Optional[str], Any]]:
# Don't show SQLAlchemy private attributes
Expand All @@ -583,7 +584,7 @@ def __repr_args__(self) -> Sequence[Tuple[Optional[str], Any]]:
@classmethod
def validate(cls: Type[_TSQLModel], value: Any) -> _TSQLModel:
if isinstance(value, cls):
return value.copy() if cls.__config__.copy_on_model_validation else value
return value.model_copy() if cls.__config__.copy_on_model_validation else value

value = cls._enforce_dict_if_root(value)
if isinstance(value, dict):
Expand Down Expand Up @@ -619,18 +620,18 @@ def _calculate_keys(
# Updated to not return SQLAlchemy attributes
# Do not include relationships as that would easily lead to infinite
# recursion, or traversing the whole database
return self.__fields__.keys() # | self.__sqlmodel_relationships__.keys()
return self.model_fields.keys() # | self.__sqlmodel_relationships__.keys()

keys: AbstractSet[str]
if exclude_unset:
keys = self.__fields_set__.copy()
keys = self.model_fields_set.copy()
else:
# Original in Pydantic:
# keys = self.__dict__.keys()
# Updated to not return SQLAlchemy attributes
# Do not include relationships as that would easily lead to infinite
# recursion, or traversing the whole database
keys = self.__fields__.keys() # | self.__sqlmodel_relationships__.keys()
keys = self.model_fields.keys() # | self.__sqlmodel_relationships__.keys()
if include is not None:
keys &= include.keys()

Expand Down