Skip to content

Commit b0840b6

Browse files
committed
fix: set unknown size to sys.maxsize
Users may length check a QuerySet as part of a normal workflow. A len of 0 would be misleading, indicating to the user that there are no matches for the endpoint and/or filters they supplied. __len__ must return a non-negative int. Sentinel values such as -1 or None do not work. This only leaves maxsize as the possible flag.
1 parent 81e653c commit b0840b6

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

tableauserverclient/server/query.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ class QuerySet(Iterable[T], Sized):
4848
QuerySet is needed. The length of the QuerySet is the total number of items
4949
available in the QuerySet, not just the number of items that have been
5050
fetched. If the endpoint does not return a total count of items, the length
51-
of the QuerySet will be None. If there is no total count, the QuerySet will
52-
continue to fetch items until there are no more items to fetch.
51+
of the QuerySet will be sys.maxsize. If there is no total count, the
52+
QuerySet will continue to fetch items until there are no more items to
53+
fetch.
5354
5455
QuerySet is not re-entrant. It is not designed to be used in multiple places
5556
at the same time. If you need to use a QuerySet in multiple places, you
@@ -158,7 +159,7 @@ def _fetch_all(self: Self) -> None:
158159
self._pagination_item = PaginationItem()
159160

160161
def __len__(self: Self) -> int:
161-
return self.total_available or 0
162+
return self.total_available or sys.maxsize
162163

163164
@property
164165
def total_available(self: Self) -> int:

test/test_flowruns.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import unittest
23
import xml.etree.ElementTree as ET
34

@@ -121,4 +122,4 @@ def test_queryset(self) -> None:
121122
m.get(f"{self.baseurl}?pageNumber=1", text=response_xml)
122123
m.get(f"{self.baseurl}?pageNumber=2", text=error_response)
123124
queryset = self.server.flow_runs.all()
124-
assert len(queryset) == 0
125+
assert len(queryset) == sys.maxsize

0 commit comments

Comments
 (0)