Skip to content

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

Backlog

Description

@0xeriiic

hash_id_columns accepts an iterable, but an iterator is consumed by the first call to hash_record(). Later rows are hashed without the requested columns, so distinct rows can get the same primary key.

from sqlite_utils import Database

table = Database(memory=True, execute_plugins=False)["inventory"]
table.insert_all(
    [{"code": "a", "quantity": 1}, {"code": "b", "quantity": 2}],
    hash_id_columns=iter(["code"]),
)
print(list(table.rows))

The second row gets the hash of an empty record on main at 74c0b6c. Passing ['code'] produces the intended IDs for both rows. Reproduced on Python 3.13 on Windows. OpenAI Codex assisted with investigation, testing, and this draft.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions