duckdb icon indicating copy to clipboard operation
duckdb copied to clipboard

Result of sql(..).execute() still refers to local context variables.

Open soerenwolfers opened this issue 2 years ago • 2 comments

What happens?

The relation returned by duckdb.sql(..).execute() still refers to local context variables, such that if it is used in a different context (e.g., after being returned by a function) it can either fail or return unwanted results.

(see https://github.com/duckdb/duckdb/discussions/10962 for context)

To Reproduce

import duckdb
def f():
    a = duckdb.sql('SELECT * from range(1)').execute()
    b = duckdb.sql("SELECT * FROM a").execute()
    return b
print(f())
InvalidInputException: Invalid Input Error: Attempting to execute an unsuccessful or closed pending query result
Error: Catalog Error: Table with name a does not exist!
Did you mean "pg_am"?

Even worse

import duckdb
def f():
    a = duckdb.sql('SELECT * from range(1)').execute()
    b = duckdb.sql("SELECT * FROM a").execute()
    return b
a = duckdb.sql('SELECT * FROM range(2)')
print(f())
┌───────┐
│ range │
│ int64 │
├───────┤
│     0 │
│     1 │
└───────┘

OS:

Linux

DuckDB Version:

0.10.1-dev126

DuckDB Client:

Python

Full Name:

Soeren Wolfers

Affiliation:

G-Research

Have you tried this on the latest nightly build?

I have tested with a nightly build

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • [X] Yes, I have

soerenwolfers avatar Mar 18 '24 16:03 soerenwolfers

Thanks for the report, I believe I discovered this issue myself a couple days ago, if it's the same issue I am aware of the cause and am working on a fix 👍

Tishj avatar Mar 26 '24 18:03 Tishj

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jul 02 '24 00:07 github-actions[bot]

Both queries now return a single row (with value 0)

soerenwolfers avatar Jul 17 '24 12:07 soerenwolfers