Skip to content

Commit 11544a3

Browse files
jacalataclaude
andcommitted
Raise server errors other than 400006 when iterating a QuerySet
QuerySet.__iter__ caught every ServerResponseError but only handled 400006, so any other error (for example 400065 for a filter value with a comma) ended the loop with no items instead of raising. Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent fbda5b9 commit 11544a3

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎tableauserverclient/server/query.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def __iter__(self: Self) -> Iterator[T]:
8787
# error and return to cleanly end the generator.
8888
# (raise StopIteration would cause RuntimeError per PEP 479)
8989
return
90+
raise
9091
if len(self._result_cache) == 0:
9192
return
9293
yield from self._result_cache

‎test/test_pager.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,19 @@ def get(self, req_options=None):
169169
# Before the fix this raised: RuntimeError: generator raised StopIteration
170170
results = [x for x in qs]
171171
assert len(results) == 1
172+
173+
174+
def test_queryset_iteration_raises_other_server_errors() -> None:
175+
"""Iterating must surface server errors other than 400006, not yield nothing."""
176+
from tableauserverclient.server.endpoint.exceptions import ServerResponseError
177+
from tableauserverclient.server.query import QuerySet
178+
179+
class MockEndpoint:
180+
def get(self, req_options=None):
181+
raise ServerResponseError("400065", "Bad Request", "Error parsing filter query", "http://test")
182+
183+
qs: QuerySet[TSC.ProjectItem] = QuerySet(MockEndpoint()) # type: ignore[arg-type]
184+
185+
with pytest.raises(ServerResponseError) as excinfo:
186+
[x for x in qs]
187+
assert excinfo.value.code == "400065"

0 commit comments

Comments
 (0)