Skip to content

Avoid mutating ErrorTree on missing child lookup#1495

Closed
mconsalvo95-tech wants to merge 1 commit into
python-jsonschema:mainfrom
mconsalvo95-tech:codex/fix-error-tree-getitem
Closed

Avoid mutating ErrorTree on missing child lookup#1495
mconsalvo95-tech wants to merge 1 commit into
python-jsonschema:mainfrom
mconsalvo95-tech:codex/fix-error-tree-getitem

Conversation

@mconsalvo95-tech

Copy link
Copy Markdown

Fixes #1328.

This replaces ErrorTree's internal defaultdict child storage with an explicit dictionary so reading a valid child with no errors does not persist an empty subtree. Existing error paths are still populated during construction, and invalid indices still propagate the underlying instance lookup error.

Tests:

  • uv run --group test python -m unittest jsonschema.tests.test_exceptions
  • PYTHONUTF8=1 JSON_SCHEMA_TEST_SUITE=json uv run --group test virtue jsonschema
  • uv run --with ruff ruff check jsonschema\exceptions.py jsonschema\tests\test_exceptions.py

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 python-jsonschema | 🛠️ Build #33098311 | 📁 Comparing 9dbb982 against latest (1a77549)

  🔍 Preview build  

1 file changed
± _modules/jsonschema/exceptions/index.html

@mconsalvo95-tech

Copy link
Copy Markdown
Author

Closing this after noticing that #1457 already addresses the same ErrorTree behavior. Sorry for the duplicate.

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.

The return of __iter__() and __contains__() change after accessing of an index with no error

1 participant