Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

Version History
===============
v1.8.8 (2026-11-16)
--------------------

* Fix ``RecursionError`` in ``Cursor._do_execute()`` for long-running jobs by polling iteratively instead of recursively

v1.7.0 (2026-01-29)
--------------------

Expand Down
15 changes: 7 additions & 8 deletions tdclient/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def _check_executed(self) -> None:
def _do_execute(self) -> None:
self._check_executed()
assert self._executed is not None
if self._rows is None:
# Poll iteratively (not recursively) so long-running jobs cannot exceed Python's recursion limit.
while self._rows is None:
status = self._api.job_status(self._executed)
if status == "success":
self._rows = self._api.job_result(self._executed)
Expand All @@ -85,14 +86,12 @@ def _do_execute(self) -> None:
self._description = self._result_description(
job.get("hive_result_schema", [])
)
elif status in ["error", "killed"]:
raise errors.InternalError(f"job error: {self._executed}: {status}")
else:
if status in ["error", "killed"]:
raise errors.InternalError(f"job error: {self._executed}: {status}")
else:
time.sleep(self.wait_interval)
if callable(self.wait_callback):
self.wait_callback(self)
return self._do_execute()
time.sleep(self.wait_interval)
if callable(self.wait_callback):
self.wait_callback(self)

def _result_description(
self, result_schema: list[Any] | None
Expand Down
22 changes: 22 additions & 0 deletions tdclient/test/cursor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,25 @@ def test_cursor_setoutputsize():
td = cursor.Cursor(mock.MagicMock())
with pytest.raises(errors.NotSupportedError) as error:
td.setoutputsize(42)


def test_do_execute_wait_exceeds_recursion_limit():
# Polling must be iterative: many polls must not hit RecursionError.
import sys

polls = sys.getrecursionlimit() * 2
td = cursor.Cursor(
mock.MagicMock(),
db="sample_datasets",
wait_interval=5,
wait_callback=mock.MagicMock(),
)
td._executed = "42"
td.api.job_status = mock.MagicMock(side_effect=["running"] * polls + ["success"])
td.api.job_result = mock.MagicMock(return_value=[["foo", 1]])
td.api.show_job = mock.MagicMock(return_value={"hive_result_schema": []})
with mock.patch("time.sleep") as t_sleep:
td._do_execute()
assert t_sleep.call_count == polls
assert td.wait_callback.call_count == polls
assert td._rowcount == 1
Loading