unevaluatedProperties error gets raised before more relevant validation errors
メンテナーはふだん 6 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
提供されたスキーマを jsonschema.validate と Draft202012Validator.validate で再現し、その後 jsonschema/_utils.py の find_evaluated_property_keys_by_schema と jsonschema/exceptions.py のエラー選択ロジックを調べます。得られたエラーを比較し、unevaluatedProperties がより関連性の高いサブスキーマの検証エラーをマスクしないようにする方法を判断します。例が一貫して最大の違反を報告すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Hello!
I noticed that in schemas using 'allOf' and unevaluatedProperties, when there is an error in a subschema, instead of showing the relevant error, unevaluatedProperties is (sometimes?) shown instead. This makes it really hard to see what went wrong in anything larger than trivial examples. This seems to be related to https://github.com/python-jsonschema/jsonschema/issues/1074, just with a different scenario.
Here is a small example:
import jsonschema
obj = {
"fridge_min_temp": 10
}
schema = {
"type": "object",
"allOf": [
{
"properties": {
"fridge_min_temp": { "type": "integer", "minimum": -20, "maximum": 5 }
},
"required": ["fridge_min_temp"]
}
],
"unevaluatedProperties": False
}
jsonschema.validate(obj, schema)
Which produces the error trace:
ValidationError: Unevaluated properties are not allowed ('fridge_min_temp' was unexpected)
Failed validating 'unevaluatedProperties' in schema:
{'allOf': [{'properties': {'fridge_min_temp': {'maximum': 5,
'minimum': -20,
...
'type': 'object',
'unevaluatedProperties': False}
On instance:
{'fridge_min_temp': 10}
If I validate instead using:
jsonschema.Draft202012Validator(schema).validate(obj)
Then the raised error is much more helpful:
ValidationError: 10 is greater than the maximum of 5
Failed validating 'maximum' in schema['allOf'][0]['properties']['fridge_min_temp']:
{'maximum': 5, 'minimum': -20, 'type': 'integer'}
On instance['fridge_min_temp']:
10
Seems like this happens because jsonschema.validate is equivalent to raise best_match(jsonschema.Draft202012Validator(schema).iter_errors(obj)) in this case, and the best_match heuristic downgrades any errors coming from 'allOf' and 'oneOf'.
With a more complex schema, I get an unevaluatedProperties error using both approaches.
3 ways of going about it could be:
-
The suggestion from https://github.com/python-jsonschema/jsonschema/issues/1074 to separately keep track of unevaluated properties and invalid properties, and write different error messages for them.
-
Add properties to evaluated keys even if there are errors resulting from
validator.descendin https://github.com/python-jsonschema/jsonschema/blob/main/jsonschema/_utils.py:
def find_evaluated_property_keys_by_schema(validator, instance, schema):
# ...
for keyword in ["allOf", "oneOf", "anyOf"]:
if keyword in schema:
for subschema in schema[keyword]:
errs = next(validator.descend(instance, subschema), None)
if errs is None:
evaluated_keys += find_evaluated_property_keys_by_schema(
validator, instance, subschema,
)
This way unevaluatedProperties will not get raised for properties with subschema errors at all (which shouldn't be a problem, because it'll get raised when those errors are fixed).
- Make
unevaluatedPropertiesmessages even weaker than "allOf" and "anyOf" related errors in https://github.com/python-jsonschema/jsonschema/blob/main/jsonschema/exceptions.py#L19
I'd be happy to attempt a PR; do you have any thoughts about which approach is best?
- 主要言語
- Python
- スター
- 5k
- フォーク
- 741
- 平均マージ
- 4日 17時間
- マージ済み PR(30日)
- 6
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python-jsonschema/jsonschema のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
python-jsonschema/jsonschema#1610 · コメント 1 件 ·
メンテナーはふだん 6 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
python-jsonschema/jsonschema#1588 · コメント 2 件 ·
メンテナーはふだん 6 日以内に返信
-
Iterator error contexts lose parent links and absolute paths再び着手できるかも @DawnofGenX が 59 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
python-jsonschema/jsonschema#1584 · コメント 3 件 ·
メンテナーはふだん 6 日以内に返信
-
regex format checker crashes with RecursionError on deeply nested patterns対応中かも @DawnofGenX が 59 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
python-jsonschema/jsonschema#1538 · コメント 1 件 ·
メンテナーはふだん 6 日以内に返信
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponent再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンNeeds Test Upstream
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
python-jsonschema/jsonschema#1511 · コメント 1 件 ·
メンテナーはふだん 6 日以内に返信
python-jsonschema/jsonschema の issue をすべて見る
似ている issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
web-push-libs/pywebpush#216 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
AgriciDaniel/claude-seo#572 ·
メンテナーはふだん 5 日以内に返信
-
area:print-dispatch
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
メンテナーはふだん 1 日以内に返信
-
area: docs domain: technical-writing good first issue type: documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
Deepak3699/Ai_Mentor#919 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信