Skip to content

Commit bf9b439

Browse files
Detect execution errors earlier, avoiding the unhelpful "attempting to execute an unsuccessful or closed pending query result" errors (#41)
This PR fixes duckdb/duckdb#18106
2 parents 55dfa2c + 2d9dffa commit bf9b439

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/duckdb_py/pyconnection.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ shared_ptr<DuckDBPyConnection> DuckDBPyConnection::ExecuteMany(const py::object
465465

466466
unique_ptr<QueryResult> DuckDBPyConnection::CompletePendingQuery(PendingQueryResult &pending_query) {
467467
PendingExecutionResult execution_result;
468+
if (pending_query.HasError()) {
469+
pending_query.ThrowError();
470+
}
468471
while (!PendingQueryResult::IsResultReady(execution_result = pending_query.ExecuteTask())) {
469472
{
470473
py::gil_scoped_acquire gil;

tests/fast/udf/test_remove_function.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def func(x: int) -> int:
5252
Error: Catalog Error: Scalar Function with name func does not exist!
5353
"""
5454
with pytest.raises(
55-
duckdb.InvalidInputException, match='Attempting to execute an unsuccessful or closed pending query result'
55+
duckdb.CatalogException, match='Scalar Function with name func does not exist!'
5656
):
5757
res = rel.fetchall()
5858

@@ -72,7 +72,7 @@ def also_func(x: int) -> int:
7272
return x
7373

7474
con.create_function('func', also_func)
75-
with pytest.raises(duckdb.InvalidInputException, match='No function matches the given name'):
75+
with pytest.raises(duckdb.BinderException, match='No function matches the given name'):
7676
res = rel2.fetchall()
7777

7878
def test_overwrite_name(self):
@@ -98,7 +98,7 @@ def other_func(x):
9898
con.remove_function('func')
9999

100100
with pytest.raises(
101-
duckdb.InvalidInputException, match='Catalog Error: Scalar Function with name func does not exist!'
101+
duckdb.CatalogException, match='Catalog Error: Scalar Function with name func does not exist!'
102102
):
103103
# Attempted to execute the relation using the 'func' function, but it was deleted
104104
rel1.fetchall()

0 commit comments

Comments
 (0)