sqlite3.Connection.iterdump() can lose AUTOINCREMENT counters after a temporary table is dropped
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 62/100
調査の方向性
バグは Lib/sqlite3/dump.py にあります。ダンプ用のクエリ SELECT * FROM "sqlite_sequence" が、main ではなく残存している temp.sqlite_sequence に解決されています。まず issue のスナップショットで再現させ、そのうえでクエリを main.sqlite_sequence と修飾し、出力された ('invoices', 2) の INSERT を確認してください。復元したデータベースが ID 3 を割り当て、iterdump() の前に削除された一時 AUTOINCREMENT テーブルをリグレッションテストがカバーしていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Bug report
Restoring a database from Connection.iterdump() can cause an AUTOINCREMENT table to reuse a previously issued ID. This happens even when the temporary table that triggered the problem had a different name and was dropped before the dump.
import sqlite3
source = sqlite3.connect(":memory:")
source.executescript("""
CREATE TABLE invoices(id INTEGER PRIMARY KEY AUTOINCREMENT);
INSERT INTO invoices DEFAULT VALUES;
INSERT INTO invoices DEFAULT VALUES;
DELETE FROM invoices WHERE id = 2;
CREATE TEMP TABLE staging(id INTEGER PRIMARY KEY AUTOINCREMENT);
DROP TABLE temp.staging;
""")
restored = sqlite3.connect(":memory:")
restored.executescript("\n".join(source.iterdump()))
for db in (source, restored):
print(db.execute("INSERT INTO invoices DEFAULT VALUES").lastrowid)
Expected: both inserts allocate ID 3.
Actual: the source allocates ID 3 and the restored database reuses ID 2.
Before the insert, both databases contain only invoice 1 and both pass PRAGMA integrity_check. A copy made with Connection.backup() correctly allocates ID 3. Removing the two staging-table statements also makes the SQL restore allocate ID 3.
Creating the temporary table leaves an empty temp.sqlite_sequence behind after the table is dropped. In Lib/sqlite3/dump.py, SELECT * FROM "sqlite_sequence" resolves to that temporary table. The dump consequently emits DELETE FROM "sqlite_sequence" without the INSERT that would restore the ('invoices', 2) counter. Qualifying the source query as main.sqlite_sequence fixes this reproducer.
CPython versions tested on:
3.12, 3.13, 3.14, 3.15, 3.16, CPython main branch
Operating systems tested on:
Linux
- 主要言語
- Python
- スター
- 78.4k
- フォーク
- 36.6k
- 平均マージ
- 1日 5時間
- マージ済み PR(30日)
- 615
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
python/cpython#162603 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Document importlib.metadata.Distribution.at()対応中かも @jaypratpsinghbhadoria が 1 日前に担当しました。 オープンdocs topic-importlib
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Item assignment and deletion raise `IndexError` instead of `TypeError` on types without them, for a huge index再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンinterpreter-core pending type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
python/cpython#162466 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
stdlib topic-subprocess type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
corner case: base64.b32decode ignorechars=b'=' miscounts padding対応中かも @ElDShell が 3 日前に担当しました。 オープン3.15 easy type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
python/cpython#162353 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
vllm-project/vllm#70030 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
TigreGotico/tugaphone#408 ·
メンテナーはふだん 1 日以内に返信
-
t: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
needs-triage
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
Azure/azure-sdk-for-python#50155 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信