Skip to content

Commit

Permalink
Better fix for #2871, fixes #2872.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Apr 17, 2024
1 parent b0404ee commit ec87d30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 1 addition & 4 deletions peewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,7 @@ def iterator(self, database=None):
return iter(self.execute(database).iterator())

def _ensure_execution(self):
if not self._cursor_wrapper:
if self._cursor_wrapper is None:
if not self._database:
raise ValueError('Query has not been executed.')
self.execute()
Expand Down Expand Up @@ -4572,9 +4572,6 @@ def __len__(self):
self.fill_cache()
return self.count

def __bool__(self):
return self.populated

def initialize(self):
pass

Expand Down
10 changes: 10 additions & 0 deletions tests/regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1801,3 +1801,13 @@ def run(n):
for i in (0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.5)]
for t in threads: t.start()
for t in threads: t.join()


class TestQueryCountList(ModelTestCase):
requires = [User]

def test_iteration_single_query(self):
with self.assertQueryCount(1):
list(User.select())
with self.assertQueryCount(1):
self.assertEqual(User.select().count(), 0)

0 comments on commit ec87d30

Please sign in to comment.