Skip to content

Not assigning cursor from DuckDBPyConnection.cursor() causes Connection Error when fetching data #315

@provinzkraut

Description

@provinzkraut

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?

  • Yes, I have

Did you include all relevant configuration to reproduce the issue?

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions