Skip to content

Preserve iterator-backed hash ID columns - #992

Open
0xeriiic wants to merge 1 commit into
simonw:mainfrom
0xeriiic:fix-hash-id-columns-iterator
Open

0xeriiic wants to merge 1 commit into
simonw:mainfrom
0xeriiic:fix-hash-id-columns-iterator

Conversation

@0xeriiic

@0xeriiic 0xeriiic commented Dec 4, 2026

Copy link
Copy Markdown

Fixes #991

Snapshot one-shot hash_id_columns inputs before using them to hash rows or saving them as defaults. The selected columns are then available for every row and for later inserts using the same table defaults.

The regression tests cover an iterator passed directly to insert_all(), an iterator passed to db.table(), and an iterator passed to table.create(). All 12 targeted hash ID tests passed in both SQLite connection modes on Python 3.13 and Windows.

OpenAI Codex assisted with reproducing the bug, writing the change and regression tests, and preparing this draft.

AI assistance: OpenAI Codex.

@atishay-kasliwal atishay-kasliwal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All 3 new test cases fail on main and pass here. tests/test_create.py goes from 219 to 222 passed.

I also ran three rows through the paths that take hash_id_columns, with iter(["code"]) or a generator: insert_all (default and batch_size=1), upsert_all, db.table(..., hash_id_columns=...) then insert_all, and create(..., hash_id_columns=...) then insert_all. On main, the insert paths raise UNIQUE constraint failed: t.id. Here every path gives the three expected hash_record(row, ["code"]) ids, and dict_keys works on both branches.

The upsert_all case on main is worse than the issue says: there's no error, it just leaves 2 rows out of 3, because the 2nd and 3rd rows hash to the same id and the 3rd overwrites the 2nd. The new test only covers insert_all, so an upsert_all case might be worth adding, since that's where the bug lost data silently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One-shot iterators passed as hash_id_columns produce incorrect IDs after the first row

2 participants