From 47c65e7ecb481a2311608f19d5a77e92a71dbab2 Mon Sep 17 00:00:00 2001 From: Eddie A Tejeda <669988+eddietejeda@users.noreply.github.com> Date: Thu, 19 Nov 2026 11:12:18 -0800 Subject: [PATCH] fix(query): cap the arrow follow read at the row guard Send limit = max_auto_rows + 1 when following a result as Arrow, so an oversized result is not downloaded only to be discarded. --- hotdata/query.py | 5 ++++- tests/test_query_arrow.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hotdata/query.py b/hotdata/query.py index 317ddc2..4ebc5b6 100644 --- a/hotdata/query.py +++ b/hotdata/query.py @@ -759,8 +759,11 @@ def _follow_arrow( batches = [] fetched = 0 + # Ask for one row past the guard at most: enough to detect the overflow, + # without downloading an oversized result only to discard it. + limit = max_auto_rows + 1 if max_auto_rows is not None else None with _ArrowResultsApi(self.api_client).stream_result_arrow( - result_id, x_database_id, _request_timeout=_request_timeout + result_id, x_database_id, limit=limit, _request_timeout=_request_timeout ) as reader: for batch in reader: fetched += batch.num_rows diff --git a/tests/test_query_arrow.py b/tests/test_query_arrow.py index 717878e..2f37545 100644 --- a/tests/test_query_arrow.py +++ b/tests/test_query_arrow.py @@ -301,6 +301,8 @@ def test_follow_row_guard_holds_when_run_lookup_fails(calls: Any) -> None: with pytest.raises(ResultTooLargeError) as ei: _api().query_arrow(REQ, x_database_id="db1", max_auto_rows=2) assert ei.value.observed == 3 + # The read asks for one row past the guard, not the whole result. + assert "limit=3" in calls[3]["url"] def test_follow_survives_failed_run_lookup(calls: Any) -> None: