Skip to content

Support whole document operations on scalar documents (#213) - #219

Open
stefankoegl wants to merge 2 commits into
masterfrom
claude/tender-noether-ps9xr3
Open

stefankoegl wants to merge 2 commits into
masterfrom
claude/tender-noether-ps9xr3

Conversation

@stefankoegl

Copy link
Copy Markdown
Owner

A JSON document can be a scalar, but operations on the whole document
(path "") raised a bare TypeError for one, which is not part of the
documented exceptions:

  • 'add' (and 'copy', which goes through it) to "" now replaces the
    document whatever its type, as 'replace' already did.
  • 'remove' of "" now raises JsonPatchConflict for every type of document,
    instead of a TypeError for scalars and a misleading "non-existent
    object 'None'" / "invalid array index 'None'" for objects and arrays.
  • 'move' from "" resolves the whole document as 'copy' does, so moving
    it onto itself is a no-op and moving it elsewhere fails with
    JsonPatchConflict. This also removes the TypeError for array documents
    from move does not reject moving an array element into its own children, and crashes when moving the whole array #214; its check for moves into a location's own children is
    still missing.

The TypeError branches in 'replace' could no longer be reached and are
removed. test_whole_document_as_target now holds;
test_raises_only_documented_exceptions still fails, only because of #215.

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

claude added 2 commits October 9, 2026 22:07
A JSON document can be a scalar, but operations on the whole document
(path "") raised a bare TypeError for one, which is not part of the
documented exceptions:

- 'add' (and 'copy', which goes through it) to "" now replaces the
  document whatever its type, as 'replace' already did.
- 'remove' of "" now raises JsonPatchConflict for every type of document,
  instead of a TypeError for scalars and a misleading "non-existent
  object 'None'" / "invalid array index 'None'" for objects and arrays.
- 'move' from "" resolves the whole document as 'copy' does, so moving
  it onto itself is a no-op and moving it elsewhere fails with
  JsonPatchConflict. This also removes the TypeError for array documents
  from #214; its check for moves into a location's own children is
  still missing.

The TypeError branches in 'replace' could no longer be reached and are
removed. test_whole_document_as_target now holds;
test_raises_only_documented_exceptions still fails, only because of #215.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01964EYaTCKUya9tcPjhytDq
master now rejects moves into a location's own children (#214), which
also covers 'move' from "". Resolved by keeping master's MoveOperation:
it returns early when 'from' is "", so the whole-document branch this
branch had added there is dropped as unreachable. The comment on the
'move' from "" example keeps master's reference to #214.

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

This branch has not been deployed

No deployments
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.

2 participants