Repository navigation
gh-162646: preserve AUTOINCREMENT counters in iterdump() - #162662
vikash1311994 wants to merge 1 commit into
Conversation
|
Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate. Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors. We believe this contribution does not meet our guidelines for using AI tools, so we're closing it. If you think we've misunderstood your contribution, please let us know. You're welcome to explain your approach or ask questions about the guidelines. Please read our guidelines for using AI tools. |
|
wrong label, sorry |
|
Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate. Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors. This contribution appears to have been authored with AI assistance. Please explain your contribution in your own words and describe how you checked its correctness. Please read our guidelines for using AI tools. |
Fixes #162646.
Root cause
_iterdump()readsSELECT * FROM "sqlite_sequence"without a schema qualifier. SQLite resolves unqualified table names by searchingtempbeforemain. Creating and dropping a temporaryAUTOINCREMENTtable leaves an emptytemp.sqlite_sequencebehind, so the dump sees zero rows, emits onlyDELETE FROM "sqlite_sequence", and omits theINSERTstatements that restore the counters. A database restored from that dump then reuses IDs that were already issued (reproduced: source allocates 3, restored allocates 2).Fix
Qualify the query as
SELECT * FROM main."sqlite_sequence";.mainis the schema the rest ofiterdump()already reads viasqlite_master, so the dump now reads the counters from the same database it is dumping.Tests
DumpTests.test_dump_autoincrement_with_temp_tableinLib/test/test_sqlite3/test_dump.py: after a temp AUTOINCREMENT table is created and dropped, both the source and a database restored fromiterdump()allocate id 3.AssertionError: 2 != 3); with the fix restored, it passes../python -m test test_sqlite3: 530 run, 4 skipped, 0 failures.Misc/NEWS.d/next/Library/entry for sqlite3.Connection.iterdump() can lose AUTOINCREMENT counters after a temporary table is dropped #162646.Risk
Low. One pure-Python query change in
Lib/sqlite3/dump.py; no C code, no schema changes, no API changes. Databases without a leftovertemp.sqlite_sequenceproduce identical dumps.Explicitly excluded
DELETE FROM "sqlite_sequence"/INSERT INTO "sqlite_sequence" ...statements: they are replayed into the destination database, where qualifying them would change existing dump output and is unnecessary here.mainonly.Note for maintainers: the CPython CLA check may be pending on my account; I will complete the CLA personally if required.