Fix collerk/ormar#588 bug in querysetproxy count() method
This commit is contained in:
@ -26,7 +26,7 @@ class QuerySetProtocol(Protocol): # pragma: nocover
|
|||||||
async def exists(self) -> bool:
|
async def exists(self) -> bool:
|
||||||
...
|
...
|
||||||
|
|
||||||
async def count(self) -> int:
|
async def count(self, distinct: bool = True) -> int:
|
||||||
...
|
...
|
||||||
|
|
||||||
async def clear(self) -> int:
|
async def clear(self) -> int:
|
||||||
|
|||||||
@ -682,6 +682,12 @@ class QuerySet(Generic[T]):
|
|||||||
"""
|
"""
|
||||||
Returns number of rows matching the given criteria
|
Returns number of rows matching the given criteria
|
||||||
(applied with `filter` and `exclude` if set before).
|
(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`,
|
||||||
|
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).
|
||||||
|
`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
|
||||||
|
|
||||||
:return: number of rows
|
:return: number of rows
|
||||||
:rtype: int
|
:rtype: int
|
||||||
|
|||||||
@ -193,17 +193,22 @@ class QuerysetProxy(Generic[T]):
|
|||||||
"""
|
"""
|
||||||
return await self.queryset.exists()
|
return await self.queryset.exists()
|
||||||
|
|
||||||
async def count(self) -> int:
|
async def count(self, distinct: bool = True) -> int:
|
||||||
"""
|
"""
|
||||||
Returns number of rows matching the given criteria
|
Returns number of rows matching the given criteria
|
||||||
(applied with `filter` and `exclude` if set before).
|
(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`,
|
||||||
|
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).
|
||||||
|
`False` is the legacy (buggy) behavior for workflows that depend on it.
|
||||||
|
|
||||||
Actual call delegated to QuerySet.
|
Actual call delegated to QuerySet.
|
||||||
|
|
||||||
|
:param distinct: flag if the primary table rows should be distinct or not
|
||||||
:return: number of rows
|
:return: number of rows
|
||||||
:rtype: int
|
:rtype: int
|
||||||
"""
|
"""
|
||||||
return await self.queryset.count()
|
return await self.queryset.count(distinct=distinct)
|
||||||
|
|
||||||
async def max(self, columns: Union[str, List[str]]) -> Any: # noqa: A003
|
async def max(self, columns: Union[str, List[str]]) -> Any: # noqa: A003
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user