Skip to content

Optimization & bug fixes, additional parameters in update methods

Choose a tag to compare

@collerek collerek released this 06 Apr 12:27
· 1121 commits to master since this release
e553885

0.10.2

✨ Features

  • Model.save_related(follow=False) now accept also two additional arguments: Model.save_related(follow=False, save_all=False, exclude=None).
    • save_all:bool -> By default (so with save_all=False) ormar only upserts models that are not saved (so new or updated ones),
      with save_all=True all related models are saved, regardless of saved status, which might be useful if updated
      models comes from api call, so are not changed in the backend.
    • exclude: Union[Set, Dict, None] -> set/dict of relations to exclude from save, those relation won't be saved even with follow=True and save_all=True.
      To exclude nested relations pass a nested dictionary like: exclude={"child":{"sub_child": {"exclude_sub_child_realtion"}}}. The allowed values follow
      the fields/exclude_fields (from QuerySet) methods schema so when in doubt you can refer to docs in queries -> selecting subset of fields -> fields.
  • Model.update() method now accepts _columns: List[str] = None parameter, that accepts list of column names to update. If passed only those columns will be updated in database.
    Note that update() does not refresh the instance of the Model, so if you change more columns than you pass in _columns list your Model instance will have different values than the database!
  • Model.dict() method previously included only directly related models or nested models if they were not nullable and not virtual,
    now all related models not previously visited without loops are included in dict(). This should be not breaking
    as just more data will be dumped to dict, but it should not be missing.
  • QuerySet.delete(each=False, **kwargs) previously required that you either pass a filter (by **kwargs or as a separate filter() call) or set each=True now also accepts
    exclude() calls that generates NOT filter. So either each=True needs to be set to delete whole table or at least one of filter/exclude clauses.
  • Same thing applies to QuerySet.update(each=False, **kwargs) which also previously required that you either pass a filter (by **kwargs or as a separate filter() call) or set each=True now also accepts
    exclude() calls that generates NOT filter. So either each=True needs to be set to update whole table or at least one of filter/exclude clauses.
  • Same thing applies to QuerysetProxy.update(each=False, **kwargs) which also previously required that you either pass a filter (by **kwargs or as a separate filter() call) or set each=True now also accepts
    exclude() calls that generates NOT filter. So either each=True needs to be set to update whole table or at least one of filter/exclude clauses.

🐛 Fixes

  • Fix improper relation field resolution in QuerysetProxy if fk column has different database alias.
  • 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
  • Fix wrong merging of deeply nested chain of reversed relations

💬 Other

  • Performance optimizations
  • Split tests into packages based on tested area