Skip to content

insert_all() with list rows and hash_id= stores values in the wrong columns #997

Backlog

Description

@YouKnowChatta

table.insert_all() and table.upsert_all() accept rows as lists or tuples, with the column names first. With hash_id= or hash_id_columns=, no hash is computed and each value is stored one column to the left. This reproduces with sqlite-utils 4.2.2 and on main at ced72c7:

from sqlite_utils import Database

db = Database(memory=True)
dogs = db["dogs"]
dogs.insert_all([["name", "twitter"], ["Cleo", "cleopaws"]], hash_id="id")
print(list(dogs.rows))
print(dogs.last_pk)

Actual output:

[{'id': 'Cleo', 'name': 'cleopaws', 'twitter': None}]
Cleo

Expected output, the same as for dogs.insert_all([{"name": "Cleo", "twitter": "cleopaws"}], hash_id="id"). The hash matches the example in the hash_id documentation:

[{'id': 'f501265970505d9825d8d9f590bfab3519fb20b1', 'name': 'Cleo', 'twitter': 'cleopaws'}]
f501265970505d9825d8d9f590bfab3519fb20b1

Rows that start with the same value get the same id. The second such row raises sqlite3.IntegrityError: UNIQUE constraint failed: dogs.id, and with ignore=True it is skipped without an error. upsert_all() stores the same shifted values. After a single-row upsert, last_pk is None (with use_old_upsert=True it is the row's first value).

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