fix: list-mode insert_all/upsert_all with hash_id misaligns values - #880
Closed
harsh-thakkar7 wants to merge 1 commit into
Closed
harsh-thakkar7 wants to merge 1 commit into
harsh-thakkar7 wants to merge 1 commit into
Conversation
When insert_all() or upsert_all() received lists of values plus an auto-generated hash_id, all_columns had the hash column prepended but the raw rows were then paired against that expanded list. Every value shifted one column to the left and the hash_id column ended up holding the first value instead of a key, e.g. rows (1, 'x') became (1, 'x', NULL) under columns (id, a, b). Compute the hash from the user-declared values and prepend it so columns stay aligned.
Author
|
Closing this — I don't think this change is mature enough to land right now. Thanks for the project! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
insert_all()/upsert_all()in list mode (records as lists, first yielded list is the column names) misassigned every row whenhash_id=was used:insert_all()correctly madeidthe first column, but the raw row lists were then paired against that expanded column list — so the value that should have been the hash key was stuffed intoid, the data columns all slid left, and the last column wentNULL. The stored rows are also silently wrong (no hash was ever computed).Fix
In list mode, when
hash_idis set, compute the hash from the user-declared values (dict(zip(user_columns, row))) and prepend it, so value positions stay aligned withall_columns. Short rows are still padded withNoneand long rows truncated — but only against the user-declared columns, before the hash is computed.The stored hash keys now match exactly what dict-mode
hash_idproduces for the same data, and the values stay in their correct columns:[{'id': '6773f537...', 'a': 1, 'b': 'x'}, {'id': '150c1d4a...', 'a': 2, 'b': 'y'}]Tests
Added to
tests/test_list_mode.py:test_insert_all_list_mode_with_hash_id_aligns_values— values land in the right columns andidis the correct hash for each row (fails before this change).test_insert_all_list_mode_with_hash_id_pads_and_truncates— short rows are padded before hashing; over-long rows are truncated.test_upsert_all_list_mode_with_hash_id— same guarantees for upserts.📚 Documentation preview 📚: https://sqlite-utils--880.org.readthedocs.build/en/880/