wip pc problems backup
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
import uuid
|
||||
from typing import Dict, Optional, Set, TYPE_CHECKING
|
||||
|
||||
import pydantic
|
||||
|
||||
import ormar
|
||||
from ormar.exceptions import ModelPersistenceError
|
||||
from ormar.models.helpers.validation import validate_choices
|
||||
@ -50,11 +53,30 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
|
||||
pkname = cls.Meta.pkname
|
||||
pk = cls.Meta.model_fields[pkname]
|
||||
if new_kwargs.get(pkname, ormar.Undefined) is None and (
|
||||
pk.nullable or pk.autoincrement
|
||||
pk.nullable or pk.autoincrement
|
||||
):
|
||||
del new_kwargs[pkname]
|
||||
return new_kwargs
|
||||
|
||||
@classmethod
|
||||
def parse_non_db_fields(cls, model_dict: Dict) -> Dict:
|
||||
"""
|
||||
Receives dictionary of model that is about to be saved and changes uuid fields
|
||||
to strings in bulk_update.
|
||||
|
||||
:param model_dict: dictionary of model that is about to be saved
|
||||
:type model_dict: Dict
|
||||
:return: dictionary of model that is about to be saved
|
||||
:rtype: Dict
|
||||
"""
|
||||
for name, field in cls.Meta.model_fields.items():
|
||||
if field.__type__ == uuid.UUID and name in model_dict:
|
||||
if field.column_type.uuid_format == "string":
|
||||
model_dict[name] = str(model_dict[name])
|
||||
else:
|
||||
model_dict[name] = "%.32x" % model_dict[name].int
|
||||
return model_dict
|
||||
|
||||
@classmethod
|
||||
def substitute_models_with_pks(cls, model_dict: Dict) -> Dict: # noqa CCR001
|
||||
"""
|
||||
@ -104,9 +126,9 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
|
||||
"""
|
||||
for field_name, field in cls.Meta.model_fields.items():
|
||||
if (
|
||||
field_name not in new_kwargs
|
||||
and field.has_default(use_server=False)
|
||||
and not field.pydantic_only
|
||||
field_name not in new_kwargs
|
||||
and field.has_default(use_server=False)
|
||||
and not field.pydantic_only
|
||||
):
|
||||
new_kwargs[field_name] = field.get_default()
|
||||
# clear fields with server_default set as None
|
||||
|
||||
Reference in New Issue
Block a user