question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect SchemaError for enum schema with unique elements

See original GitHub issue
# Draft7 for convenience; the same applies to 3, 4, and 6.
# We can have a unique list of things that compare equal, e.g. this works:
jsonschema.Draft7Validator.check_schema({'enum': [False, 0.0]})

# But wrap them in a one-element list, and we get a `SchemaError` instead!
jsonschema.Draft7Validator.check_schema({'enum': [[False], [0.0]]})

There are IMO two bugs here:

  1. JSON values are being tested for equality using Python object semantics, rather than comparing them as JSON (e.g. via a canonical encoding).

  2. The json-schema specification says

     The value of this keyword MUST be an array.
     This array SHOULD have at least one element.
     Elements in the array SHOULD be unique.
    

    Validation therefore ought to allow schema authors to use empty or non-unique arrays, because the RFC 2119 definition of SHOULD explicitly permits ignoring such clauses after considering the circumstances.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
erohmensingcommented, Nov 8, 2022

@Julian thanks for the “for archeological purposes”, rest assured it’s worth adding as people still run into this strange mismatch years later 😄

1reaction
Juliancommented, Nov 1, 2022

I mentioned this briefly on https://github.com/json-schema-org/json-schema-spec/issues/717#issuecomment-1299112660 but just for archaeological purposes, this change was just partially “backed out” for drafts 3 and 4 where indeed the original behavior (MUST) was correct, those drafts contain stronger language. It’s definitely correct on newer ones though (so thanks again for filing it!)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Json schema validation error - Stack Overflow
Therefore you receive an error about wrong type. JSON schema type MUST be single value or array of such strings: "array","boolean","integer"," ...
Read more >
Handling Validation Errors - python-jsonschema
In case an invalid schema itself is encountered, a SchemaError is raised. exception jsonschema.exceptions.SchemaError(message, validator=<unset>, path=(), ...
Read more >
Re: Dependencies between two "enums" - Google Groups
The problem here is with your schema. First you tell it to reference to one definition _but then_ you constrain it with an...
Read more >
Understanding JSON Schema
element is unique. In this case, the JSON snippet is valid if it matches any of the given types. Here is a simple...
Read more >
schema - PyPI
validate(data). This method may raise SchemaError exception, which will tell Schema that that piece of data is invalid, otherwise—it will continue validating.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found