Draft 0.11.0 (#594)
* 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
This commit is contained in:
@ -56,7 +56,6 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
|
||||
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
|
||||
|
||||
|
||||
@ -23,8 +23,7 @@ import databases
|
||||
import pydantic
|
||||
import sqlalchemy
|
||||
|
||||
from ormar.fields.parsers import encode_json
|
||||
from ormar.models.utils import Extra
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
@ -32,6 +31,7 @@ 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 (
|
||||
@ -40,6 +40,7 @@ from ormar.models.helpers.sqlalchemy import (
|
||||
)
|
||||
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
|
||||
|
||||
@ -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
|
||||
@ -45,11 +45,17 @@ class FieldAccessor:
|
||||
: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,
|
||||
|
||||
@ -682,9 +682,11 @@ class QuerySet(Generic[T]):
|
||||
"""
|
||||
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
|
||||
@ -695,7 +697,9 @@ class QuerySet(Generic[T]):
|
||||
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)
|
||||
|
||||
|
||||
@ -198,9 +198,11 @@ class QuerysetProxy(Generic[T]):
|
||||
"""
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user