Behavior when attempting to *override* an official dialect is not well defined when recursing into subschemas containing the official dialect's $schema identifier

Ouverte
#994 25 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 6 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
json, python
Domaine
backend, testing-qa

Piste de recherche

Commencez dans jsonschema/validators.py avec evolve (vers les lignes 222-238) et validator_for (vers la ligne 1143), puis reproduisez le comportement avec l’exemple asdf schema.check_schema. Suivez la validation récursive du sous-schéma imbriqué et comparez le mapping VALIDATORS du validateur. Le travail est terminé lorsque le ValidationError attendu est rétabli et que la couverture de régression capture le comportement du validateur de valeurs par défaut personnalisé.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Dialects v2 Enhancement

This is related to part of https://github.com/python-jsonschema/jsonschema/issues/981#issuecomment-1219713160; namely, the broken validation of default values in asdf. However, I believe the issue itself originates in the evolve: https://github.com/python-jsonschema/jsonschema/blob/2f15a98f9243b77ff8f546e8b28cbbdabd7fef23/jsonschema/validators.py#L222-L238 method first introduced in version 4.10.0.

Essentially, we are creating a a new validator using the Draft4Validator, which contains an additional validators function (under the default keyword). See https://github.com/asdf-format/asdf/blob/bf954a3921df6b3e5f36c211c18257ac97d4f423/asdf/schema.py#L705-L750 in the asdf code. However, it appears that the additional default validator is being lost when attempting to validate something. The following should produce a ValidationError with the latest version of asdf:

from asdf import schema

s = {"type": "object", "properties": {"a": {"type": "integer", "default": "foo"}}}

schema.check_schema(s)

Indeed, if one has jsonschema 4.9.1 installed, one gets a ValidationError; however, if one has jsonschema 4.15.0 installed, one gets no validation error.

After carefully stepping the the code as it is running with jsonschema 4.15.0 I have found that at some point while iterating, the evolve method returns a validator class which does not have default in its VALIDATORS attribute when it should have one. Making it so that there is no validator available when it does try to validate default. This occurs when validator_for does not return DefaultValidator: https://github.com/python-jsonschema/jsonschema/blob/2f15a98f9243b77ff8f546e8b28cbbdabd7fef23/jsonschema/validators.py#L1143 Instead it returns the Draft4Validator which does not contain default in its VALIDATORS dictionary. Meaning the validator returned by evolve has now lost the default validator for further iterations.

Langage dominant
Python
Étoiles
5k
Forks
741
Merge moyen
4 j 17 h
PR mergées (30 j)
6

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de python-jsonschema/jsonschema

Toutes les issues de python-jsonschema/jsonschema

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.