Skip to content

Commit

Permalink
Fix double requests when calling list(q) on py3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
craigds committed Jul 30, 2021
1 parent 6cfe5e6 commit 7e60a18
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions koordinates/base.py
Expand Up @@ -231,10 +231,16 @@ def __len__(self):
Get the count for the query results. If we've previously started iterating we use
that count, otherwise do a request and look at the ``X-Resource-Range`` header.
"""
# note: this method is called twice when wrapping queries in list(), from py3.8+
# https://bugs.python.org/issue39829
# so we need to make sure it is cached and doesn't do a request every time.
if self._count is None:
r = self._request(self._to_url())
self._update_range(r)
self._first_page = (r.json(), self._next_url(r))
if self._count is None and self._first_page[1] is None:
# this is the only page
self._count = len(self._first_page[0])
return self._count

def __getitem__(self, k):
Expand Down

0 comments on commit 7e60a18

Please sign in to comment.