fix bulk_create trying to save property fields and pydantic fields
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
* Fix hitting recursion error with very complicated models structure with loops when calling `dict()`.
|
||||
* Fix bug when two non-relation fields were merged (appended) in query result when they were not relation fields (i.e. JSON)
|
||||
* Fix bug when during translation to dict from list the same relation name is used in chain but leads to different models
|
||||
* Fix bug when bulk_create would try to save also `property_field` decorated methods and `pydantic` fields
|
||||
|
||||
## Other
|
||||
|
||||
|
||||
@ -32,11 +32,29 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
|
||||
:rtype: Dict[str, str]
|
||||
"""
|
||||
new_kwargs = cls._remove_pk_from_kwargs(new_kwargs)
|
||||
new_kwargs = cls._remove_not_ormar_fields(new_kwargs)
|
||||
new_kwargs = cls.substitute_models_with_pks(new_kwargs)
|
||||
new_kwargs = cls.populate_default_values(new_kwargs)
|
||||
new_kwargs = cls.translate_columns_to_aliases(new_kwargs)
|
||||
return new_kwargs
|
||||
|
||||
@classmethod
|
||||
def _remove_not_ormar_fields(cls, new_kwargs: dict) -> dict:
|
||||
"""
|
||||
Removes primary key for if it's nullable or autoincrement pk field,
|
||||
and it's set to None.
|
||||
|
||||
:param new_kwargs: dictionary of model that is about to be saved
|
||||
:type new_kwargs: Dict[str, str]
|
||||
:return: dictionary of model that is about to be saved
|
||||
:rtype: Dict[str, str]
|
||||
"""
|
||||
ormar_fields = {
|
||||
k for k, v in cls.Meta.model_fields.items() if not v.pydantic_only
|
||||
}
|
||||
new_kwargs = {k: v for k, v in new_kwargs.items() if k in ormar_fields}
|
||||
return new_kwargs
|
||||
|
||||
@classmethod
|
||||
def _remove_pk_from_kwargs(cls, new_kwargs: dict) -> dict:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user