Skip to content

🐛 Make Library.remove atomic and tolerant of changed block keys - #607

Merged
MiWeiss merged 4 commits into
mainfrom
fix/library-remove-changed-key
Sep 2, 2026
Merged

MiWeiss merged 4 commits into
mainfrom
fix/library-remove-changed-key

Conversation

@MiWeiss

@MiWeiss MiWeiss commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Library.remove deletes from _blocks before the key dicts. Keys are mutable, so a renamed block raises KeyError after it has already been dropped.

>>> e = lib.entries[0]; e.key = "renamed"; lib.remove(e)
KeyError: 'a'
>>> len(lib.blocks), sorted(lib.entries_dict)
(1, ['a', 'c'])   # gone from blocks, still in the key dict

The documented contract is ValueError. replace inherits this, and list removal was non-atomic.

Fix: resolve all indices and key registrations first, mutate after. Registrations are found by identity, falling back to the key, so renames de-register correctly. remove is now atomic, mirroring add.

Tests: 6 cases, 4 fail before. Suite 2582 passed, from 2576.


🤖 Generated with Claude Code

@MiWeiss
MiWeiss force-pushed the fix/library-remove-changed-key branch 3 times, most recently from 488c802 to 99d5aa1 Compare September 2, 2026 20:00
remove() deleted the block from _blocks before deleting it from the
by-key dicts, and looked the dict entry up via block.key. A key changed
after adding thus raised a raw KeyError (instead of the documented
ValueError) and left the library half-modified. Removal now resolves the
block index and its by-key registration (by identity, falling back to
the key) before mutating anything, so failures leave the library
unchanged and a list removal with a missing block is atomic, as in add().

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@MiWeiss
MiWeiss force-pushed the fix/library-remove-changed-key branch from 99d5aa1 to 51ba76a Compare September 2, 2026 20:03
@MiWeiss

MiWeiss commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

lgtm

MiWeiss and others added 2 commits September 2, 2026 22:27
docstr-coverage requires a docstring on the nested helper; the hook is
not part of the local test run, so CI caught it first.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@MiWeiss
MiWeiss force-pushed the fix/library-remove-changed-key branch from b8f56b4 to e06b1dd Compare September 2, 2026 20:38
@MiWeiss
MiWeiss merged commit f7d2644 into main Sep 2, 2026
16 checks passed
@MiWeiss
MiWeiss deleted the fix/library-remove-changed-key branch September 10, 2026 20:04
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