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

オープン
#994 コメント 25 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 6 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
json, python

調査の方向性

jsonschema/validators.py の evolve(222-238 行付近)と validator_for(1143 行付近)から始め、その後 asdf schema.check_schema の例で動作を再現します。ネストされたサブスキーマの再帰的なバリデーションを追跡し、validator の VALIDATORS マッピングを比較します。期待される ValidationError が復元され、回帰テストのカバレッジでカスタムデフォルトバリデータの動作が捉えられれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
5k
フォーク
741
平均マージ
4日 17時間
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-jsonschema/jsonschema のほかの issue

python-jsonschema/jsonschema の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。