Skip to content

Commit bca08ba

Browse files
authored
fix: put special fields first (#1622)
Closes #1620 Sorting the fields prior to putting them in the query string assures that '_all_' and '_default_' appear first in the field list, satisfying the criteria of Tableau Server/Cloud to process those first. Order of other fields appeared to be irrelevant, so the test simply ensures their presence. Co-authored-by: Jordan Woods <[email protected]>
1 parent 755ddec commit bca08ba

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

tableauserverclient/server/request_options.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ def get_query_params(self) -> dict:
9696
if self.pagesize:
9797
params["pageSize"] = self.pagesize
9898
if self.fields:
99-
params["fields"] = ",".join(self.fields)
99+
if "_all_" in self.fields:
100+
params["fields"] = "_all_"
101+
else:
102+
params["fields"] = ",".join(sorted(self.fields))
100103
return params
101104

102105
def page_size(self, page_size):

test/test_request_option.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,27 @@ def test_queryset_only_fields(self) -> None:
378378
loop = self.server.users.only_fields("id")
379379
assert "id" in loop.request_options.fields
380380
assert "_default_" not in loop.request_options.fields
381+
382+
def test_queryset_field_order(self) -> None:
383+
with requests_mock.mock() as m:
384+
m.get(self.server.views.baseurl, text=SLICING_QUERYSET_PAGE_1.read_text())
385+
loop = self.server.views.fields("id", "name")
386+
list(loop)
387+
history = m.request_history[0]
388+
389+
fields = history.qs.get("fields", [""])[0].split(",")
390+
391+
assert fields[0] == "_default_"
392+
assert "id" in fields
393+
assert "name" in fields
394+
395+
def test_queryset_field_all(self) -> None:
396+
with requests_mock.mock() as m:
397+
m.get(self.server.views.baseurl, text=SLICING_QUERYSET_PAGE_1.read_text())
398+
loop = self.server.views.fields("id", "name", "_all_")
399+
list(loop)
400+
history = m.request_history[0]
401+
402+
fields = history.qs.get("fields", [""])[0]
403+
404+
assert fields == "_all_"

0 commit comments

Comments
 (0)