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 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 6 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
json, python

研究方向

從 jsonschema/validators.py 中的 evolve(約第 222-238 行)和 validator_for(約第 1143 行)開始,然後使用 asdf schema.check_schema 範例重現該行為。追蹤巢狀 subschema 的遞迴驗證,並比較 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 小時
30 天內合併 PR
6

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

python-jsonschema/jsonschema 的其他 Issue

查看 python-jsonschema/jsonschema 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。