Iterator error contexts lose parent links and absolute paths

Open Beginner friendly
#1,584 3 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

@DawnofGenX is already working on this.

Since Oct 5, 2026.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Start by locating the ValidationError and SchemaError constructors and reproduce the iterator example from the issue. Inspect the existing regression tests for context and parent behavior, then cover one-shot iterator contexts for both error classes alongside list and tuple contexts. Done means children retain their parent links and produce absolute paths including the parent path.

Written by the indexing model from the issue text.

Description

Problem

Passing an iterator as ValidationError(context=...) retains its children, but does not set their parent. The iterator is consumed by self.context = list(context), then iterated again when assigning parents. This also affects SchemaError.

from jsonschema.exceptions import ValidationError

child = ValidationError("child", path=["name"], schema_path=[0, "type"])
parent = ValidationError(
    "parent",
    path=["record"],
    schema_path=["properties", "record", "anyOf"],
    context=iter([child]),
)
print(parent.context == [child])  # True
print(child.parent is parent)    # False (expected True)
print(child.json_path)           # $.name (expected $.record.name)

Lists and tuples assign the parent correctly. Setting parents from the stored self.context instead of the original iterable should preserve the same behavior for one-shot iterators.

Reproduced on main (51cd75e39), macOS, Python 3.12.13. A regression test fails for iterator contexts with both error classes and passes for list/tuple contexts.

Investigated with Codex assistance.

Dominant language
Python
Stars
5k
Forks
741
Avg merge
4d 17h
Merged PRs (30d)
6

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python-jsonschema/jsonschema

All issues in python-jsonschema/jsonschema

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.