sqlite3.Connection.iterdump() can lose AUTOINCREMENT counters after a temporary table is dropped
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 62/100
Línea de trabajo
El error está en Lib/sqlite3/dump.py, donde la consulta de volcado SELECT * FROM "sqlite_sequence" se resuelve en un temp.sqlite_sequence sobrante en lugar de main. Empieza reproduciendo el problema con el fragmento del issue; después, califica la consulta como main.sqlite_sequence y comprueba el INSERT generado para ('invoices', 2). Está terminado cuando la base de datos restaurada asigna el ID 3 y una prueba de regresión cubre una tabla AUTOINCREMENT temporal eliminada antes de iterdump().
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 78.4k
- Forks
- 36.6k
- Merge medio
- 1 d 5 h
- PR fusionados (30 d)
- 615
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python/cpython
-
docs
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
python/cpython#162603 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Document importlib.metadata.Distribution.at()Posiblemente ocupada @jaypratpsinghbhadoria la tomó hace 1 día. Abiertodocs topic-importlib
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Item assignment and deletion raise `IndexError` instead of `TypeError` on types without them, for a huge indexQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertointerpreter-core pending type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
python/cpython#162466 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
stdlib topic-subprocess type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
corner case: base64.b32decode ignorechars=b'=' miscounts paddingPosiblemente ocupada @ElDShell la tomó hace 3 días. Abierto3.15 easy type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
python/cpython#162353 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de python/cpython
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
vllm-project/vllm#70030 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
TigreGotico/tugaphone#408 ·
Los mantenedores suelen responder en 1 día
-
t: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 3 días
-
needs-triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Azure/azure-sdk-for-python#50155 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día