refactor: migrate from jsonschema.RefResolver to referencing#2716
refactor: migrate from jsonschema.RefResolver to referencing#2716henryiii wants to merge 1 commit into
Conversation
jsonschema.RefResolver has been deprecated since jsonschema 4.18. Replace it with a referencing.Registry plus a retrieve callback that loads pyhf schemas from disk, and pass registry=... to the validator instead of the deprecated resolver=... argument. Because the pyhf schemas carry a top-level $ref (e.g. model.json points at defs.json#/definitions/model), draft-06's sibling-$ref rules suppress the root $id, so the resolver base URI is set explicitly to the schema $id. A new loader.read_schema reads schemas without touching SCHEMA_CACHE so that resolving $refs does not pollute the cache (preserving existing caching behavior, including the custom schema-path context manager). Bump jsonschema>=4.18.0 and add referencing as an explicit dependency in both the project and pixi dependency tables, and drop the now-unneeded RefResolver DeprecationWarning filter. Assisted-by: ClaudeCode:claude-opus-4.8
|
Warning Review limit reached
More reviews will be available in 17 minutes and 47 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2716 +/- ##
==========================================
- Coverage 98.28% 96.47% -1.81%
==========================================
Files 65 65
Lines 4305 4315 +10
Branches 465 465
==========================================
- Hits 4231 4163 -68
- Misses 46 119 +73
- Partials 28 33 +5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🤖 AI text below 🤖
Part of the code review in #2706.
Resolves #2139.
Summary
jsonschema.RefResolverhas been deprecated since jsonschema 4.18. This migrates pyhf's schema validation to thereferencinglibrary:src/pyhf/schema/validator.pynow builds areferencing.Registrywith aretrievecallback (_retrieve_schema) that loads referenced schemas from disk, and passesregistry=...to thejsonschemavalidator instead of the deprecatedresolver=....$ref(e.g.model.json->defs.json#/definitions/model). Under draft-06, a sibling$refsuppresses$id, so jsonschema cannot infer the root schema's base URI. The resolver base URI is therefore anchored explicitly to the schema$idso relative references likedefs.jsonresolve correctly.loader.read_schemareads a schema directly from disk without consulting or mutatingSCHEMA_CACHE, so resolving$refs does not pollute the cache. This preserves the existing caching semantics, including thepyhf.schema(new_path)custom-schema-path context manager and theInvalidSpecificationexception behavior.jsonschema>=4.15.0->jsonschema>=4.18.0and addedreferencing>=0.28.4as an explicit dependency in both the project and pixi dependency tables (it is now imported directly).RefResolverDeprecationWarningfilter. Since pytest runs withfilterwarnings=error, any remaining deprecation path would now fail the suite.Test plan
uv pip install --group dev --editable .pytest tests/test_schema.py(70 passed)pytest tests/test_workspace.py tests/test_pdf.py(308 passed, 6 skipped)pytest tests/test_validation.py tests/test_patchset.py tests/test_public_api.py(all pass)pytest --doctest-modules src/pyhf/schema/(3 passed)prek -a(lint clean)🤖 Generated with Claude Code