Skip to content

fix(exceptions): count duplicate-validator errors in ErrorTree#1476

Closed
Bojun-Vvibe wants to merge 1 commit intopython-jsonschema:mainfrom
Bojun-Vvibe:fix/python-jsonschema-jsonschema-442
Closed

fix(exceptions): count duplicate-validator errors in ErrorTree#1476
Bojun-Vvibe wants to merge 1 commit intopython-jsonschema:mainfrom
Bojun-Vvibe:fix/python-jsonschema-jsonschema-442

Conversation

@Bojun-Vvibe
Copy link
Copy Markdown

Closes #442

Repo

python-jsonschema/jsonschema

Issue

#442

Root cause

ErrorTree.errors is a dict keyed by error.validator, so when multiple
ValidationErrors at the same path share the same validator keyword (e.g.
several "type" failures), later ones overwrite earlier ones. Because
total_errors was computed as len(self.errors) + child_errors, those
collapsed errors were silently undercounted.

Fix

Keep the per-validator errors dict for backward compatibility, but also
append every incoming error to a new internal _all_errors list and use
len(self._all_errors) in total_errors. Surgical change in
jsonschema/exceptions.py (ErrorTree.__init__ and total_errors).

Regression test

jsonschema/tests/test_exceptions.py::TestErrorTree::test_total_errors_counts_duplicate_validators
asserts that an ErrorTree built from three ValidationErrors sharing
validator="type" reports total_errors == 3 (was 1 before the fix).

Risk

low

Verification

Ran PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 python -m pytest jsonschema/tests/test_exceptions.py -q — 60 passed, 0 failed.

ErrorTree.total_errors used len(self.errors), but self.errors is a
dict keyed by validator keyword, so multiple errors at the same path
sharing a validator (e.g. several 'type' failures) were collapsed and
undercounted. Track every error in an internal list and use its
length for total_errors.
@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 python-jsonschema | 🛠️ Build #32383682 | 📁 Comparing e663964 against latest (ad0a1b3)

  🔍 Preview build  

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

@Julian Julian closed this Apr 26, 2026
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.

ErrorTree assumes one error per validator

2 participants