Skip to content

🐛 Make Entry dict access symmetric for ENTRYTYPE and ID#561

Merged
MiWeiss merged 2 commits into
mainfrom
fix/532-setitem-entrytype-id
Jun 12, 2026
Merged

🐛 Make Entry dict access symmetric for ENTRYTYPE and ID#561
MiWeiss merged 2 commits into
mainfrom
fix/532-setitem-entrytype-id

Conversation

@MiWeiss

@MiWeiss MiWeiss commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Fixes #532

entry[ENTRYTYPE] / entry[ID] return entry_type / key, but the corresponding assignment created a literal Field(ENTRYTYPE, ...). The bogus field was shadowed by __getitem__ on read (so e[ENTRYTYPE] = book; e[ENTRYTYPE] still returned article) and serialized as a regular ENTRYTYPE = book line on write. Particularly dangerous for v1 migrators, where assigning these dict keys was the documented way to change an entry type or key.

Changes

  • __setitem__ mirrors __getitem__: ENTRYTYPE and ID set entry_type / key instead of creating a field. Mirroring (rather than raising) was chosen because these dunders exist precisely for v1 compatibility, and mirroring restores the dict invariant e[k] = v ⟹ e[k] == v with exactly the v1 semantics.
  • __contains__ had the same asymmetry (ENTRYTYPE in entry was False although entry[ENTRYTYPE] succeeds and items() lists it); it now returns True for the two magic keys.
  • Deliberately untouched: get()/pop() (they return Field objects, and there is no sensible Field for the entry type) and __delitem__ (deleting the entry type is nonsensical; it keeps harmlessly no-op-ing).

A literal field named ENTRYTYPE/ID can still be created via set_field() / fields if anyone genuinely needs that; only the dict-mimicking shorthand routes to the properties.

🤖 Generated with Claude Code

MiWeiss and others added 2 commits June 12, 2026 13:13
`entry[ENTRYTYPE]` / `entry[ID]` returned `entry_type` / `key`,
but the corresponding assignment created a literal field that was
shadowed on read and serialized as a regular field (e.g.
`ENTRYTYPE = book`) on write. Particularly dangerous for v1
migrators, where these dict keys were the documented way to change
an entry type or key.

`__setitem__` now mirrors `__getitem__` and sets `entry_type` /
`key`; `__contains__` now reports the two keys as contained,
consistent with `__getitem__` and `items()`.

Fixes #532

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@MiWeiss MiWeiss merged commit 6d8654c into main Jun 12, 2026
31 checks passed
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.

Entry.__setitem__("ENTRYTYPE"/"ID") creates a literal field, asymmetric with __getitem__

1 participant