8000 Enable always sorting when using pager (#192) · tableau/server-client-python@47332fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 47332fc

Browse files
author
Russell Hay
authored
Enable always sorting when using pager (#192)
* Enble always sorting when using pager because queries are not currently deterministic * I forgot to format the files * Fixing tyler's nit
1 parent 735130a commit 47332fc

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

tableauserverclient/server/pager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from . import RequestOptions
2+
from . import Sort
23

34

45
class Pager(object):
@@ -16,6 +17,11 @@ def __init__(self, endpoint, request_opts=None):
1617
self._count = ((self._options.pagenumber - 1) * self._options.pagesize)
1718
else:
1819
self._count = 0
20+
self._options = RequestOptions()
21+
22+
# Pager assumes deterministic order but solr doesn't guarantee sort order unless specified
23+
if not self._options.sort:
24+
self._options.sort.add(Sort(RequestOptions.Field.Name, RequestOptions.Direction.Asc))
1925

2026
def __iter__(self):
2127
# Fetch the first page

test/test_pager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ def test_pager_with_options(self):
5555
page_3 = f.read().decode('utf-8')
5656
with requests_mock.mock() as m:
5757
# Register Pager with some pages
58-
m.get(self.baseurl + "?pageNumber=1&pageSize=1", text=page_1)
59-
m.get(self.baseurl + "?pageNumber=2&pageSize=1", text=page_2)
60-
m.get(self.baseurl + "?pageNumber=3&pageSize=1", text=page_3)
61-
m.get(self.baseurl + "?pageNumber=1&pageSize=3", text=page_1)
58+
m.get(self.baseurl + "?pageNumber=1&pageSize=1&sort=name:asc", complete_qs=True, text=page_1)
59+
m.get(self.baseurl + "?pageNumber=2&pageSize=1&sort=name:asc", complete_qs=True, text=page_2)
60+
m.get(self.baseurl + "?pageNumber=3&pageSize=1&sort=name:asc", complete_qs=True, text=page_3)
61+
m.get(self.baseurl + "?pageNumber=1&pageSize=3&sort=name:asc", complete_qs=True, text=page_1)
6262

6363
# Starting on page 2 should get 2 out of 3
6464
opts = TSC.RequestOptions(2, 1)

0 commit comments

Comments
 (0)
0