mirror of
https://github.com/Infinidat/infi.clickhouse_orm.git
synced 2024-11-25 18:23:44 +03:00
Bug fix: QuerySet.count()
ignores slicing
This commit is contained in:
parent
928e41b82c
commit
f2a731711d
|
@ -1,6 +1,10 @@
|
|||
Change Log
|
||||
==========
|
||||
|
||||
Unreleased
|
||||
----------
|
||||
- Bug fix: `QuerySet.count()` ignores slicing
|
||||
|
||||
v1.0.2
|
||||
----------
|
||||
- Include alias and materialized fields in queryset results
|
||||
|
|
|
@ -316,11 +316,12 @@ class QuerySet(object):
|
|||
"""
|
||||
Returns the number of matching model instances.
|
||||
"""
|
||||
if self._distinct:
|
||||
if self._distinct or self._limits:
|
||||
# Use a subquery, since a simple count won't be accurate
|
||||
sql = u'SELECT count() FROM (%s)' % self.as_sql()
|
||||
raw = self._database.raw(sql)
|
||||
return int(raw) if raw else 0
|
||||
# Simple case
|
||||
return self._database.count(self._model_cls, self.conditions_as_sql())
|
||||
|
||||
def order_by(self, *field_names):
|
||||
|
|
|
@ -239,6 +239,12 @@ class QuerySetTestCase(TestCaseWithData):
|
|||
for obj in qs:
|
||||
self.assertTrue(obj.num_squared == obj.num ** 2)
|
||||
|
||||
def test_count_of_slice(self):
|
||||
qs = Person.objects_in(self.database)
|
||||
self._test_qs(qs[:70], 70)
|
||||
self._test_qs(qs[70:80], 10)
|
||||
self._test_qs(qs[80:], 20)
|
||||
|
||||
|
||||
class AggregateTestCase(TestCaseWithData):
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user