Skip to content

Commit

Permalink
Draft 0.11.0 (#594)
Browse files Browse the repository at this point in the history
* fix for #584

* fix for #580

* fix typing

* connect to db in test

* refactor test

* remove async mark

* connect client

* fix mypy

* fix mypy

* update deps

* check py3.10?

* remove py3.6, bump version
  • Loading branch information
collerek authored Mar 28, 2022
1 parent 8376b66 commit 90f78e2
Show file tree
Hide file tree
Showing 12 changed files with 623 additions and 603 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'collerek/ormar'
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9, "3.10"]
fail-fast: false
services:
mysql:
Expand Down
18 changes: 18 additions & 0 deletions docs/releases.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
# 0.11.0

## ✨ Breaking Changes

* Dropped support for python 3.6
* `Queryset.get_or_create` returns now a tuple with model and bool value indicating if the model was created (by @MojixCoder - thanks!) [#554](https://github.com/collerek/ormar/pull/554)
* `Queryset.count()` now counts the number of distinct parent model rows by default, counting all rows is possible by setting `distinct=False` (by @erichaydel - thanks) [#588](https://github.com/collerek/ormar/pull/588)

## ✨ Features

* Added support for python 3.10

## 🐛 Fixes

* Fix inconsistent `JSON` fields behaviour in `save` and `bulk_create` [#584](https://github.com/collerek/ormar/issues/584)
* Fix maximum recursion error [#580](https://github.com/collerek/ormar/pull/580)


# 0.10.25

## ✨ Features
Expand Down
1 change: 0 additions & 1 deletion ormar/models/mixins/save_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def prepare_model_to_save(cls, new_kwargs: dict) -> dict:
new_kwargs = cls.substitute_models_with_pks(new_kwargs)
new_kwargs = cls.populate_default_values(new_kwargs)
new_kwargs = cls.reconvert_str_to_bytes(new_kwargs)
new_kwargs = cls.dump_all_json_fields_to_str(new_kwargs)
new_kwargs = cls.translate_columns_to_aliases(new_kwargs)
return new_kwargs

Expand Down
5 changes: 3 additions & 2 deletions ormar/models/newbasemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
import pydantic
import sqlalchemy

from ormar.fields.parsers import encode_json
from ormar.models.utils import Extra

from pydantic import BaseModel


import ormar # noqa I100
from ormar.exceptions import ModelError, ModelPersistenceError
from ormar.fields import BaseField
from ormar.fields.foreign_key import ForeignKeyField
from ormar.fields.parsers import encode_json
from ormar.models.helpers import register_relation_in_alias_manager
from ormar.models.helpers.relations import expand_reverse_relationship
from ormar.models.helpers.sqlalchemy import (
Expand All @@ -40,6 +40,7 @@
)
from ormar.models.metaclass import ModelMeta, ModelMetaclass
from ormar.models.modelproxy import ModelTableProxy
from ormar.models.utils import Extra
from ormar.queryset.utils import translate_list_to_dict
from ormar.relations.alias_manager import AliasManager
from ormar.relations.relation_manager import RelationsManager
Expand Down
14 changes: 10 additions & 4 deletions ormar/queryset/field_accessor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, TYPE_CHECKING, Type
from typing import Any, TYPE_CHECKING, Type, cast

from ormar.queryset.actions import OrderAction
from ormar.queryset.actions.filter_action import METHODS_TO_OPERATORS
Expand Down Expand Up @@ -45,11 +45,17 @@ def __getattr__(self, item: str) -> Any:
:return: FieldAccessor for field or nested model
:rtype: ormar.queryset.field_accessor.FieldAccessor
"""
if self._field and item == self._field.name:
if (
object.__getattribute__(self, "_field")
and item == object.__getattribute__(self, "_field").name
):
return self._field

if self._model and item in self._model.Meta.model_fields:
field = self._model.Meta.model_fields[item]
if (
object.__getattribute__(self, "_model")
and item in object.__getattribute__(self, "_model").Meta.model_fields
):
field = cast("Model", self._model).Meta.model_fields[item]
if field.is_relation:
return FieldAccessor(
source_model=self._source_model,
Expand Down
10 changes: 7 additions & 3 deletions ormar/queryset/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,11 @@ async def count(self, distinct: bool = True) -> int:
"""
Returns number of rows matching the given criteria
(applied with `filter` and `exclude` if set before).
If `distinct` is `True` (the default), this will return the number of primary rows selected. If `False`,
If `distinct` is `True` (the default), this will return
the number of primary rows selected. If `False`,
the count will be the total number of rows returned
(including extra rows for `one-to-many` or `many-to-many` left `select_related` table joins).
(including extra rows for `one-to-many` or `many-to-many`
left `select_related` table joins).
`False` is the legacy (buggy) behavior for workflows that depend on it.
:param distinct: flag if the primary table rows should be distinct or not
Expand All @@ -695,7 +697,9 @@ async def count(self, distinct: bool = True) -> int:
expr = self.build_select_expression().alias("subquery_for_count")
expr = sqlalchemy.func.count().select().select_from(expr)
if distinct:
expr_distinct = expr.group_by(self.model_meta.pkname).alias("subquery_for_group")
expr_distinct = expr.group_by(self.model_meta.pkname).alias(
"subquery_for_group"
)
expr = sqlalchemy.func.count().select().select_from(expr_distinct)
return await self.database.fetch_val(expr)

Expand Down
6 changes: 4 additions & 2 deletions ormar/relations/querysetproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,11 @@ async def count(self, distinct: bool = True) -> int:
"""
Returns number of rows matching the given criteria
(applied with `filter` and `exclude` if set before).
If `distinct` is `True` (the default), this will return the number of primary rows selected. If `False`,
If `distinct` is `True` (the default), this will return
the number of primary rows selected. If `False`,
the count will be the total number of rows returned
(including extra rows for `one-to-many` or `many-to-many` left `select_related` table joins).
(including extra rows for `one-to-many` or `many-to-many`
left `select_related` table joins).
`False` is the legacy (buggy) behavior for workflows that depend on it.
Actual call delegated to QuerySet.
Expand Down
Loading

0 comments on commit 90f78e2

Please sign in to comment.