sqlite3.Connection.iterdump() can lose AUTOINCREMENT counters after a temporary table is dropped
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 62/100
Direção de pesquisa
O bug está em Lib/sqlite3/dump.py, onde a consulta de dump SELECT * FROM "sqlite_sequence" é resolvida para um temp.sqlite_sequence remanescente em vez de main. Comece reproduzindo o problema com o trecho da issue; depois, qualifique a consulta como main.sqlite_sequence e verifique o INSERT gerado para ('invoices', 2). Está concluído quando o banco restaurado aloca o ID 3 e um teste de regressão cobre uma tabela AUTOINCREMENT temporária removida antes de iterdump().
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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
- Linguagem predominante
- Python
- Estrelas
- 78.4k
- Forks
- 36.6k
- Merge médio
- 1d 5h
- PRs com merge (30d)
- 615
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de python/cpython
-
docs
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 78/100
python/cpython#162603 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Document importlib.metadata.Distribution.at()Talvez já em andamento @jaypratpsinghbhadoria assumiu há 1 dia. Abertadocs topic-importlib
Dificuldade 1/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
Item assignment and deletion raise `IndexError` instead of `TypeError` on types without them, for a huge indexTalvez livre de novo Um pull request para esta issue foi fechado sem ser mesclado. Abertainterpreter-core pending type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
python/cpython#162466 · 4 comentários ·
Mantenedores costumam responder em até 1 dia
-
stdlib topic-subprocess type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 1 dia
-
corner case: base64.b32decode ignorechars=b'=' miscounts paddingTalvez já em andamento @ElDShell assumiu há 3 dias. Aberta3.15 easy type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
python/cpython#162353 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de python/cpython
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
vllm-project/vllm#70030 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
TigreGotico/tugaphone#408 ·
Mantenedores costumam responder em até 1 dia
-
t: bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 3 dias
-
needs-triage
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 85/100
Azure/azure-sdk-for-python#50155 · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
Mantenedores costumam responder em até 1 dia