duckdb / duckdb/duckdb-python

`DuckDBPyRelation.query()`: reusing a virtual table name silently changes the result of an existing relation

オープン
#604 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る
needs triage
主要言語
Python
スター
187
フォーク
112
平均マージ
13時間 29分
マージ済み PR(30日)
17

説明

### What happens?

`rel.query(virtual_table_name, sql)` returns a lazy relation that re-resolves `virtual_table_name` through the connection's catalog on **every** execution. Registering the same name again from a different relation therefore changes what an already-constructed relation returns, with no error, even after that relation has been executed once.

### Why it matters

Wrong data rather than an error. For a library this rules out any fixed name, so we generate a unique random name per call, which then accumulates.

### What I would expect

One of:

1. the derived relation binds the virtual table once, at construction, so it is unaffected by later registrations; or
2. re-registering a name that a live relation depends on raises; or
3. if this is intended, a note on the [relational API docs](https://duckdb.org/docs/stable/clients/python/relational_api) saying that the name is resolved late and must not be reused.

### To Reproduce

import duckdb

con = duckdb.connect()
a = con.sql("select 1 as a")
b = con.sql("select 999 as a")

first = a.query("v", "select a from v")
print(first.fetchall()) # [(1,)]

second = b.query("v", "select a from v") # same name, unrelated relation
print(second.fetchall()) # [(999,)]

print(first.fetchall()) # [(999,)] <- silently changed

### OS:

Darwin, arm64

### DuckDB Package Version:

1.1.0, 1.2.2 and 1.5.5.

### Python Version:

3.12

### Full Name:

Francesco Bruzzesi

### Affiliation:

narwhals-dev

### What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a stable release

### Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

### Did you include all code required to reproduce the issue?

- [x] Yes, I have

### Did you include all relevant configuration to reproduce the issue?

- [x] Yes, I have

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

エントリーポイントの DuckDBPyRelation.query() から開始し、提示された Python の再現コードを一覧にあるパッケージバージョン全体で実行します。仮想テーブル名が解決されるタイミングを追跡し、その後、選択した動作に対する回帰テストを追加します。名前が再利用された後も既存の relation が暗黙的に変更されてはならない、または遅延解決の契約を relational API のドキュメントに記載する必要があります。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python, sql
領域
api, database
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。