You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Not assigning cursor from DuckDBPyConnection.cursor() causes Connection Error when fetching data #315
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:
importduckdbconn=duckdb.connect()
conn.cursor().sql("SELECT 1 as foo").fetchall()
while this works
importduckdbconn=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?
Yes, I have
Did you include all relevant configuration to reproduce the issue?
Activity
evertlammerts commentedon Feb 16, 2026
That's a bug indeed, in the relational API.
To work around, use execute():
provinzkraut commentedon Feb 16, 2026
I'm using the
.plmethod is only available on the relational api, but using the cursor as a context manager also works:Add ref to connection in relation so it doesn't get closed prematurely (
evertlammerts commentedon Feb 19, 2026
Fixed in #329