Skip to content

Don't trigger __missing__ when resolving missing mapping members - #102

Merged
stefankoegl merged 1 commit into
masterfrom
claude/pensive-cannon-kvs467
Nov 6, 2026
Merged

stefankoegl merged 1 commit into
masterfrom
claude/pensive-cannon-kvs467

Conversation

@stefankoegl

Copy link
Copy Markdown
Owner

JsonPointer.walk() indexed Mapping documents before checking whether
the member exists. For mappings with a missing hook such as
collections.defaultdict, this invoked the factory, which mutated the
document, bypassed the default of resolve_pointer() and let
set_pointer() create intermediate members even with create=False.

Check membership first for Mapping documents so absent members are
reported as missing. Objects that only implement getitem keep
their custom indexing behaviour.

Fixes #101

Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01PewzphetpXGTHDnZMZg2t2

JsonPointer.walk() indexed Mapping documents before checking whether
the member exists. For mappings with a __missing__ hook such as
collections.defaultdict, this invoked the factory, which mutated the
document, bypassed the `default` of resolve_pointer() and let
set_pointer() create intermediate members even with create=False.

Check membership first for Mapping documents so absent members are
reported as missing. Objects that only implement __getitem__ keep
their custom indexing behaviour.

Fixes #101

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PewzphetpXGTHDnZMZg2t2
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 97.74% (+0.03%) from 97.714% — claude/pensive-cannon-kvs467 into master

@stefankoegl
stefankoegl merged commit 307bed3 into master Nov 6, 2026
23 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.

Resolving a missing key in defaultdict mutates the document and ignores default

3 participants