Skip to content

Commit 12154d8

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 8c2d9bd commit 12154d8

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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
@@ -160,7 +161,7 @@ def _fetch_all(self: Self) -> None:
160161
self._pagination_item = PaginationItem()
161162

162163
def __len__(self: Self) -> int:
163-
return self.total_available or 0
164+
return self.total_available or sys.maxsize
164165

165166
@property
166167
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)