Validation errors should be able to indicate that a single error should be produced without collecting all of the details ahead of time

Open
#517 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 6 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Start by tracing the validation paths for anyOf, oneOf, and dependentRequired, then inspect how ValidationError.init receives context. Done means a validation error can be yielded without collecting all sub-errors, while its full contents are calculated only when requested.

Written by the indexing model from the issue text.

Description

Dialects v2 Enhancement Error Reporting

In general, validation is lazy -- if only one error is needed (in the sense that it is known that an instance is invalid), only one is produced.

There are however (somewhat unintentional) exceptions.

E.g.:

  • anyOf and oneOf calculate the .context of the first error they yield by calculating all sub-errors that were generated. This is because ValidationError.context needs to be provided on __init__.
  • dependentRequired, on the other hand, yields many errors, one for each missing required property (see also #119)

What's happening in these situations is that the validation function knows an error has occurred -- it wants to yield an error, but in order to do so, it needs to calculate the full details required so that the error is "complete".

We should instead have a way to indicate a validation error has occurred, but delay fully calculating its contents until/unless they are requested.

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.