Skip to content

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

Closed

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

Activity

  1. paultiq commented on Nov 5, 2025

    @paultiq
    Contributor

    A similar example is:
    duckdb.connect().sql("select * from range(10)").to_arrow_table()

    ConnectionException: Connection Error: Connection has already been closed

  2. mouzkolit commented on Nov 14, 2025

    @mouzkolit

    Maybe this is kindof related to issue #128 where I see;

    ComputeError: caught exception during execution of a Python source, exception: InvalidInputException: Invalid Input Error: Attempting to execute an unsuccessful or closed pending query result.

  3. mouzkolit commented on Jan 21, 2026

    @mouzkolit

    Hi, is there any update in this ?

  4. evertlammerts commented on Feb 19, 2026

    @evertlammerts
    Member

    Fixed in #329

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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