Skip to content

Commit 4a4bc03

Browse files
ai: apply changes for #1007 (1 review thread)
Addresses: - #4419629658 at src/databricks/sql/result_set.py:312 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
1 parent c0a02a0 commit 4a4bc03

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎src/databricks/sql/result_set.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ def convert_range(lo: int, hi: int, error: Optional[Exception]) -> None:
308308
try:
309309
rows.extend(convert(piece))
310310
return
311+
except _NON_DATA_CONVERSION_ERRORS:
312+
# Resource / interpreter failures are not row-specific: stop
313+
# bisecting and propagate, as the top-level refill does.
314+
raise
311315
except Exception as e:
312316
error = e
313317
if hi - lo == 1:

‎tests/unit/test_fetches.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,34 @@ def convert(self_, table):
794794
with self.assertRaises(InternalError):
795795
rs.fetchone()
796796

797+
def test_fetchone_memory_error_during_bisection_stops_bisecting(self):
798+
from unittest.mock import patch
799+
800+
calls = []
801+
802+
def convert(self_, table):
803+
calls.append(table.num_rows)
804+
if len(calls) == 1:
805+
raise ValueError("bad value")
806+
raise MemoryError()
807+
808+
rs = self.make_columnar_result_set(10, arraysize=4)
809+
with patch.object(
810+
ThriftResultSet,
811+
"_convert_columnar_table",
812+
autospec=True,
813+
side_effect=convert,
814+
):
815+
with self.assertRaises(MemoryError):
816+
rs.fetchone()
817+
# The full batch fails with a data error, the first half hits MemoryError:
818+
# bisection stops there instead of converting more slices.
819+
self.assertEqual(calls, [4, 2])
820+
self.assertEqual(rs._row_buffer_count(), 0)
821+
# The lost refill chunk must not be skipped silently on later fetches.
822+
with self.assertRaises(InternalError):
823+
rs.fetchone()
824+
797825
def test_fetchone_interrupted_conversion_poisons_later_fetches(self):
798826
from unittest.mock import patch
799827

0 commit comments

Comments
 (0)