From 1964ad5105bd5608af24844ec0f73052e39d2afe Mon Sep 17 00:00:00 2001 From: Evert Lammerts Date: Wed, 11 Feb 2026 17:07:00 +0100 Subject: [PATCH] Simplify GIL management for FetchRow --- src/duckdb_py/pyresult.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/duckdb_py/pyresult.cpp b/src/duckdb_py/pyresult.cpp index cc6224c2..644d6393 100644 --- a/src/duckdb_py/pyresult.cpp +++ b/src/duckdb_py/pyresult.cpp @@ -117,16 +117,13 @@ unique_ptr DuckDBPyResult::FetchNextRaw(QueryResult &query_result) { } Optional DuckDBPyResult::Fetchone() { - { - D_ASSERT(py::gil_check()); + if (!result) { + throw InvalidInputException("result closed"); + } + if (!current_chunk || chunk_offset >= current_chunk->size()) { py::gil_scoped_release release; - if (!result) { - throw InvalidInputException("result closed"); - } - if (!current_chunk || chunk_offset >= current_chunk->size()) { - current_chunk = FetchNext(*result); - chunk_offset = 0; - } + current_chunk = FetchNext(*result); + chunk_offset = 0; } if (!current_chunk || current_chunk->size() == 0) {