Skip to content

Honor truncate for empty imports - #936

Merged
simonw merged 5 commits into
simonw:mainfrom
peterolkhov:codex/truncate-empty-imports
Nov 29, 2026
Merged

simonw merged 5 commits into
simonw:mainfrom
peterolkhov:codex/truncate-empty-imports

Conversation

@peterolkhov

@peterolkhov peterolkhov commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes:

Empty input currently returns before truncate=True can clear the table. This applies truncation to empty iterables and header-only list input, using the existing delete_where() helper. Nonempty imports keep their current behavior.

Adds library and CLI regressions for empty replacements, schema/index preservation, missing tables, no-truncate calls, and malformed input. Both API and CLI docs now describe empty snapshots.

Tested locally on Python 3.13.14 / SQLite 3.53.1: pytest -v and pytest --sqlite-autocommit each passed 1,516 tests, with 16 skips. Black, flake8, mypy, Cog, codespell, and a strict Sphinx HTML build passed. SpatiaLite, compiled ext.c, pandas/numpy, and the full CI matrix were not tested.

AI assistance was used to investigate, implement, and test this change.


📚 Documentation preview 📚: https://sqlite-utils--936.org.readthedocs.build/en/936/

@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.

Empty truncate works for me through both the API and the CLI. One gap with analyze.

Comment thread sqlite_utils/db.py
first_record = next(records_iter)
except StopIteration:
if truncate:
return self.delete_where()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

insert_all([], truncate=True, analyze=True) (and --truncate --analyze) skips the ANALYZE, so on a 50 row table sqlite_stat1 still says 50 10 after the delete, while truncating to one row updates it. self.delete_where(analyze=analyze) here and on line 4802 clears it, and the test suite still passes.

simonw and others added 4 commits November 29, 2026 14:02
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@simonw simonw linked an issue Nov 29, 2026 that may be closed by this pull request
@simonw simonw added the bug Something isn't working label Nov 29, 2026
@simonw
simonw merged commit df0fc5e into simonw:main Nov 29, 2026
1 check passed
simonw added a commit that referenced this pull request Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty --truncate imports leave existing rows in place

3 participants