What happens?
When obtaining a cursor from DuckDBPyConnection.cursor(), and not assigning it to a variable, that cursor cannot be used to fetch any data, and will raise a Connection Error.
It seems that not assigning the cursor causes it to be garbage collected immediately, which should not be the case, there's still a reference being held to it.
To Reproduce
This raises _duckdb.ConnectionException: Connection Error: Connection has already been closed:
import duckdb
conn = duckdb.connect()
conn.cursor().sql("SELECT 1 as foo").fetchall()
while this works
import duckdb
conn = duckdb.connect()
cur = conn.cursor()
cur.sql("SELECT 1 as foo").fetchall()
OS:
macOS
DuckDB Package Version:
1.4.3
Python Version:
3.13.7
Full Name:
Janek Nouvertné
Affiliation:
nope
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have not tested with any build
Did you include all relevant data sets for reproducing the issue?
Yes
Did you include all code required to reproduce the issue?
Did you include all relevant configuration to reproduce the issue?