Skip to content

Calling .pl(lazy=True) Fails to extend the lifetime of the cursor being called from #161

@J-Meyers

Description

@J-Meyers

What happens?

While actually executing the duckdb query is dependent on the cursor, it seems that the lifetime isn't kept up with the lazy frame, leading to:
ComputeError: caught exception during execution of a Python source, exception: ConnectionException: Connection Error: Connection has already been closed

To Reproduce

import duckdb
def duck_pl(
    con: duckdb.DuckDBPyConnection,
    sql: str,
    params: None = None,
    lazy: bool = True,
) -> pl.LazyFrame | pl.DataFrame:
    cur = con.cursor()
    return cur.sql(sql, params=params).pl(lazy=lazy)

duck_pl(duckdb.connect(),
"""
SELECT *
FROM (VALUES ('Amsterdam', 1), ('London', 2)) cities(name, id);
""",
).collect()

OS:

Linux x86_64

DuckDB Package Version:

1.4.0

Python Version:

3.11.9

Full Name:

Julian Meyers

Affiliation:

Independent

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