Skip to content

Empty --truncate imports leave existing rows in place #935

Description

@peterolkhov

An empty snapshot leaves the old rows in place even when truncate=True is set:

from sqlite_utils import Database

db = Database(memory=True)
items = db["items"]
items.insert({"id": 1, "name": "old"}, pk="id")
items.insert_all([], truncate=True)
print(list(items.rows))
# [{"id": 1, "name": "old"}]

Expected an empty table with the existing schema. This matters when refreshing a complete snapshot: a valid empty result should remove records that no longer exist upstream.

The same happens with an empty generator and through sqlite-utils insert ... --truncate using JSON [] or a header-only CSV. Both CLI calls exit 0. Nonempty replacement works. The empty-input returns in Table.insert_all happen before truncation.

Reproduced on main 9c66bafa, Python 3.13.14, SQLite 3.53.1, macOS arm64. Malformed input should still fail without clearing the existing table; that behavior needs to stay intact.

AI assistance was used to investigate and reproduce this.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions