resolve merge conflicts
This commit is contained in:
@ -29,7 +29,7 @@ def is_field_an_forward_ref(field: "BaseField") -> bool:
|
||||
)
|
||||
|
||||
|
||||
def populate_default_options_values(
|
||||
def populate_default_options_values( # noqa: CCR001
|
||||
new_model: Type["Model"], model_fields: Dict
|
||||
) -> None:
|
||||
"""
|
||||
|
||||
@ -64,8 +64,11 @@ def convert_choices_if_needed( # noqa: CCR001
|
||||
value = value.isoformat() if not isinstance(value, str) else value
|
||||
choices = [o.isoformat() for o in field.choices]
|
||||
elif field.__type__ == pydantic.Json:
|
||||
value = json.dumps(value) if not isinstance(value, str) else value
|
||||
value = (
|
||||
json.dumps(value) if not isinstance(value, str) else re_dump_value(value)
|
||||
)
|
||||
value = value.decode("utf-8") if isinstance(value, bytes) else value
|
||||
choices = [re_dump_value(x) for x in field.choices]
|
||||
elif field.__type__ == uuid.UUID:
|
||||
value = str(value) if not isinstance(value, str) else value
|
||||
choices = [str(o) for o in field.choices]
|
||||
@ -86,6 +89,21 @@ def convert_choices_if_needed( # noqa: CCR001
|
||||
return value, choices
|
||||
|
||||
|
||||
def re_dump_value(value: str) -> str:
|
||||
"""
|
||||
Rw-dumps choices due to different string representation in orjson and json
|
||||
:param value: string to re-dump
|
||||
:type value: str
|
||||
:return: re-dumped choices
|
||||
:rtype: List[str]
|
||||
"""
|
||||
try:
|
||||
result: Union[str, bytes] = json.dumps(json.loads(value))
|
||||
except json.JSONDecodeError:
|
||||
result = value
|
||||
return result.decode("utf-8") if isinstance(result, bytes) else result
|
||||
|
||||
|
||||
def validate_choices(field: "BaseField", value: Any) -> None:
|
||||
"""
|
||||
Validates if given value is in provided choices.
|
||||
|
||||
@ -280,7 +280,7 @@ def copy_and_replace_m2m_through_model( # noqa: CFQ002
|
||||
field.create_default_through_model()
|
||||
through_class = field.through
|
||||
new_meta: ormar.ModelMeta = type( # type: ignore
|
||||
"Meta", (), dict(through_class.Meta.__dict__),
|
||||
"Meta", (), dict(through_class.Meta.__dict__)
|
||||
)
|
||||
copy_name = through_class.__name__ + attrs.get("__name__", "")
|
||||
copy_through = type(copy_name, (ormar.Model,), {"Meta": new_meta})
|
||||
@ -566,9 +566,7 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
|
||||
attrs, model_fields = extract_from_parents_definition(
|
||||
base_class=base, curr_class=mcs, attrs=attrs, model_fields=model_fields
|
||||
)
|
||||
new_model = super().__new__( # type: ignore
|
||||
mcs, name, bases, attrs
|
||||
)
|
||||
new_model = super().__new__(mcs, name, bases, attrs) # type: ignore
|
||||
|
||||
add_cached_properties(new_model)
|
||||
|
||||
@ -647,6 +645,6 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
|
||||
access_chain=item,
|
||||
)
|
||||
return FieldAccessor(
|
||||
source_model=cast(Type["Model"], self), field=field, access_chain=item,
|
||||
source_model=cast(Type["Model"], self), field=field, access_chain=item
|
||||
)
|
||||
return object.__getattribute__(self, item)
|
||||
|
||||
@ -141,7 +141,7 @@ class ExcludableMixin(RelationMixin):
|
||||
return columns
|
||||
|
||||
@classmethod
|
||||
def _update_excluded_with_related(cls, exclude: Union[Set, Dict, None],) -> Set:
|
||||
def _update_excluded_with_related(cls, exclude: Union[Set, Dict, None]) -> Set:
|
||||
"""
|
||||
Used during generation of the dict().
|
||||
To avoid cyclical references and max recurrence limit nested models have to
|
||||
|
||||
@ -51,7 +51,7 @@ class PrefetchQueryMixin(RelationMixin):
|
||||
|
||||
@staticmethod
|
||||
def get_column_name_for_id_extraction(
|
||||
parent_model: Type["Model"], reverse: bool, related: str, use_raw: bool,
|
||||
parent_model: Type["Model"], reverse: bool, related: str, use_raw: bool
|
||||
) -> str:
|
||||
"""
|
||||
Returns name of the column that should be used to extract ids from model.
|
||||
|
||||
@ -28,7 +28,7 @@ class PydanticMixin(RelationMixin):
|
||||
|
||||
@classmethod
|
||||
def get_pydantic(
|
||||
cls, *, include: Union[Set, Dict] = None, exclude: Union[Set, Dict] = None,
|
||||
cls, *, include: Union[Set, Dict] = None, exclude: Union[Set, Dict] = None
|
||||
) -> Type[pydantic.BaseModel]:
|
||||
"""
|
||||
Returns a pydantic model out of ormar model.
|
||||
|
||||
@ -1,12 +1,4 @@
|
||||
from typing import (
|
||||
Callable,
|
||||
Dict,
|
||||
List,
|
||||
Optional,
|
||||
Set,
|
||||
TYPE_CHECKING,
|
||||
cast,
|
||||
)
|
||||
from typing import Callable, Dict, List, Optional, Set, TYPE_CHECKING, cast
|
||||
|
||||
from ormar import BaseField, ForeignKeyField
|
||||
from ormar.models.traversible import NodeList
|
||||
|
||||
@ -1,5 +1,15 @@
|
||||
import uuid
|
||||
from typing import Callable, Collection, Dict, List, Optional, Set, TYPE_CHECKING, cast
|
||||
from typing import (
|
||||
Any,
|
||||
Callable,
|
||||
Collection,
|
||||
Dict,
|
||||
List,
|
||||
Optional,
|
||||
Set,
|
||||
TYPE_CHECKING,
|
||||
cast,
|
||||
)
|
||||
|
||||
import ormar
|
||||
from ormar.exceptions import ModelPersistenceError
|
||||
@ -93,7 +103,7 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
|
||||
if field.__type__ == uuid.UUID and name in model_dict:
|
||||
parsers = {"string": lambda x: str(x), "hex": lambda x: "%.32x" % x.int}
|
||||
uuid_format = field.column_type.uuid_format
|
||||
parser = parsers.get(uuid_format, lambda x: x)
|
||||
parser: Callable[..., Any] = parsers.get(uuid_format, lambda x: x)
|
||||
model_dict[name] = parser(model_dict[name])
|
||||
return model_dict
|
||||
|
||||
@ -222,7 +232,7 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
|
||||
|
||||
@staticmethod
|
||||
async def _upsert_through_model(
|
||||
instance: "Model", previous_model: "Model", relation_field: "ForeignKeyField",
|
||||
instance: "Model", previous_model: "Model", relation_field: "ForeignKeyField"
|
||||
) -> None:
|
||||
"""
|
||||
Upsert through model for m2m relation.
|
||||
|
||||
@ -1,13 +1,4 @@
|
||||
from typing import (
|
||||
Any,
|
||||
Dict,
|
||||
List,
|
||||
Optional,
|
||||
Set,
|
||||
TYPE_CHECKING,
|
||||
TypeVar,
|
||||
Union,
|
||||
)
|
||||
from typing import Any, Dict, List, Optional, Set, TYPE_CHECKING, TypeVar, Union
|
||||
|
||||
import ormar.queryset # noqa I100
|
||||
from ormar.exceptions import ModelPersistenceError, NoMatch
|
||||
|
||||
@ -1,17 +1,7 @@
|
||||
from typing import (
|
||||
Any,
|
||||
Dict,
|
||||
List,
|
||||
Optional,
|
||||
TYPE_CHECKING,
|
||||
Tuple,
|
||||
Type,
|
||||
Union,
|
||||
cast,
|
||||
)
|
||||
from typing import Any, Dict, List, Optional, TYPE_CHECKING, Tuple, Type, Union, cast
|
||||
|
||||
try:
|
||||
from sqlalchemy.engine.result import ResultProxy
|
||||
from sqlalchemy.engine.result import ResultProxy # type: ignore
|
||||
except ImportError: # pragma: no cover
|
||||
from sqlalchemy.engine.result import Row as ResultProxy # type: ignore
|
||||
|
||||
@ -293,7 +283,7 @@ class ModelRow(NewBaseModel):
|
||||
"""
|
||||
through_name = cls.Meta.model_fields[related].through.get_name()
|
||||
through_child = cls._create_through_instance(
|
||||
row=row, related=related, through_name=through_name, excludable=excludable,
|
||||
row=row, related=related, through_name=through_name, excludable=excludable
|
||||
)
|
||||
|
||||
if child.__class__ != proxy_source_model:
|
||||
@ -378,7 +368,7 @@ class ModelRow(NewBaseModel):
|
||||
:rtype: Dict
|
||||
"""
|
||||
selected_columns = cls.own_table_columns(
|
||||
model=cls, excludable=excludable, alias=table_prefix, use_alias=False,
|
||||
model=cls, excludable=excludable, alias=table_prefix, use_alias=False
|
||||
)
|
||||
|
||||
column_prefix = table_prefix + "_" if table_prefix else ""
|
||||
|
||||
@ -19,17 +19,17 @@ from typing import (
|
||||
cast,
|
||||
)
|
||||
|
||||
import databases
|
||||
import pydantic
|
||||
import sqlalchemy
|
||||
from ormar.models.utils import Extra
|
||||
from pydantic import BaseModel
|
||||
|
||||
try:
|
||||
import orjson as json
|
||||
except ImportError: # pragma: no cover
|
||||
import json # type: ignore
|
||||
|
||||
import databases
|
||||
import pydantic
|
||||
import sqlalchemy
|
||||
from pydantic import BaseModel
|
||||
|
||||
import ormar # noqa I100
|
||||
from ormar.exceptions import ModelError, ModelPersistenceError
|
||||
@ -158,9 +158,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
# register the columns models after initialization
|
||||
for related in self.extract_related_names().union(self.extract_through_names()):
|
||||
model_fields[related].expand_relationship(
|
||||
new_kwargs.get(related),
|
||||
self,
|
||||
to_register=True,
|
||||
new_kwargs.get(related), self, to_register=True
|
||||
)
|
||||
|
||||
if hasattr(self, "_init_private_attributes"):
|
||||
@ -224,7 +222,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
f"need to call update_forward_refs()."
|
||||
)
|
||||
|
||||
def _process_kwargs(self, kwargs: Dict) -> Tuple[Dict, Dict]:
|
||||
def _process_kwargs(self, kwargs: Dict) -> Tuple[Dict, Dict]: # noqa: CCR001
|
||||
"""
|
||||
Initializes nested models.
|
||||
|
||||
@ -267,11 +265,8 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
k,
|
||||
self._convert_json(
|
||||
k,
|
||||
model_fields[k].expand_relationship(
|
||||
v,
|
||||
self,
|
||||
to_register=False,
|
||||
)
|
||||
model_fields[k].expand_relationship(v, self, to_register=False)
|
||||
|
||||
if k in model_fields
|
||||
else (v if k in pydantic_fields else model_fields[k]),
|
||||
),
|
||||
@ -325,8 +320,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
self,
|
||||
"_orm",
|
||||
RelationsManager(
|
||||
related_fields=self.extract_related_fields(),
|
||||
owner=cast("Model", self),
|
||||
related_fields=self.extract_related_fields(), owner=cast("Model", self)
|
||||
),
|
||||
)
|
||||
|
||||
@ -499,9 +493,7 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
|
||||
@staticmethod
|
||||
def _get_not_excluded_fields(
|
||||
fields: Union[List, Set],
|
||||
include: Optional[Dict],
|
||||
exclude: Optional[Dict],
|
||||
fields: Union[List, Set], include: Optional[Dict], exclude: Optional[Dict]
|
||||
) -> List:
|
||||
"""
|
||||
Returns related field names applying on them include and exclude set.
|
||||
|
||||
Reference in New Issue
Block a user