Skip to content

Fix: SqlBaseKvStore.__setitem__ duplicated rows instead of updating (rowcount trap left by #4) - #5

Merged
thorwhalen merged 1 commit into
masterfrom
fix/setitem-rowcount-upsert
Sep 22, 2026
Merged

thorwhalen merged 1 commit into
masterfrom
fix/setitem-rowcount-upsert

Conversation

@thorwhalen

Copy link
Copy Markdown
Member

Post-merge refute review of #4.

Defect: #4 fixed __len__ because a SELECT's rowcount is -1 on SQLite, but SqlBaseKvStore.__setitem__ still decides update-vs-insert with result.rowcount == 1 on a SELECT. On SQLite every write to an existing key is an INSERT: the table grows a duplicate row, len goes up, and store[k] (first matching row) keeps returning the old value. Now that #4 made len real, the mapping visibly breaks: store['a'] = new; store['a'] != new.

Fix: decide by whether the SELECT returns a row (.first() is not None). A key that matches rows is updated; otherwise inserted.

Tests: new sqldol/tests/test_kv_store_setitem.py (update-existing, insert-then-update-new). Both fail on master, pass here. Full suite + doctests pass locally (Python 3.10).

Not changed here (posted as design notes on #4): the default missing_key_policy='empty' still makes in answer True for every key; _mk_column_filter builds SQL by string interpolation.

Self-reviewed only (the dispatching run disallowed sub-agents).

🤖 Generated with Claude Code

…uplicated

Update-vs-insert was decided from a SELECT's rowcount, which is -1 on SQLite,
so writing an existing key always inserted a duplicate row and reads kept
returning the old value. Same rowcount trap #4 fixed in __len__.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@thorwhalen
thorwhalen merged commit da5c6ed into master Sep 22, 2026
6 checks passed
@thorwhalen
thorwhalen deleted the fix/setitem-rowcount-upsert branch September 22, 2026 14:09
thorwhalen added a commit that referenced this pull request Sep 22, 2026
)

The same rowcount trap #4 fixed in SqlBaseKvReader.__len__ and #5 fixed in
SqlBaseKvStore.__setitem__ was still in TableRows.__len__, so len() of a
TableRows over SQLite raised "ValueError: __len__() should return >= 0".
Ask the database for COUNT(*), honouring the row filter.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant