Jump to solution
Details

The Fix

pip install pydantic==1.10.18

Based on closed pydantic/pydantic issue #9933 · PR/commit linked

Open PR/Commit
@@ -2050,10 +2050,15 @@ def handle_ref_overrides(self, json_schema: JsonSchemaValue) -> JsonSchemaValue: def get_schema_from_definitions(self, json_ref: JsonRef) -> JsonSchemaValue | None: - def_ref = self.json_to_defs_refs[json_ref] - if def_ref in self._core_defs_invalid_for_json_schema: - raise self._core_defs_invalid_for_json_schema[def_ref]
fix.md
Option A — Upgrade to fixed release\npip install pydantic==1.10.18\nWhen NOT to use: This fix should not be used if external references are not required in your schema.\n\n

Why This Fix Works in Production

  • Trigger: 1. Profiling code for a variety of cases - complex models, simple models, `pydantic` imports, etc. I'm trying to identify where the most significant…
  • Mechanism: Pydantic throws a KeyError when WithJsonSchema is used with a $ref that defines an external JSON Schema via an https link
  • Why the fix works: Allows the usage of `type[Annotated[...]]` in Pydantic, addressing related issues and enhancing type handling. (first fixed release: 1.10.18).

Why This Breaks in Prod

  • Pydantic throws a KeyError when WithJsonSchema is used with a $ref that defines an external JSON Schema via an https link
  • Production symptom (often without a traceback): 1. Profiling code for a variety of cases - complex models, simple models, `pydantic` imports, etc. I'm trying to identify where the most significant bottlenecks are, and where we're doing more than we need to in terms of schema building.

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“More things for reviewing: - [x] https://github.com/pydantic/pydantic/pull/9972 - [x] https://github.com/pydantic/pydantic/pull/9971”
@sydney-runkle · 2024-07-25 · source
“I've added some additional tracking for my work this week here: https://github.com/pydantic/pydantic/issues/9965”
@sydney-runkle · 2024-07-25 · source
“Didn't get to as many of the smaller tasks as I'd hoped this week, but made some good headway on _generate_schema.py refactoring, which I find…”
@sydney-runkle · 2024-08-02 · source

Failure Signature (Search String)

  • 1. Profiling code for a variety of cases - complex models, simple models, `pydantic` imports, etc. I'm trying to identify where the most significant bottlenecks are, and where
  • - [ ] Backlog grooming for both `pydantic` and `pydantic-core`, as well as issue categorization to support easy access / entry for new contributors - pushing this to next week,
Copy-friendly signature
signature.txt
Failure Signature ----------------- 1. Profiling code for a variety of cases - complex models, simple models, `pydantic` imports, etc. I'm trying to identify where the most significant bottlenecks are, and where we're doing more than we need to in terms of schema building. - [ ] Backlog grooming for both `pydantic` and `pydantic-core`, as well as issue categorization to support easy access / entry for new contributors - pushing this to next week, perhaps with a contributing docs update as well

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- 1. Profiling code for a variety of cases - complex models, simple models, `pydantic` imports, etc. I'm trying to identify where the most significant bottlenecks are, and where we're doing more than we need to in terms of schema building. - [ ] Backlog grooming for both `pydantic` and `pydantic-core`, as well as issue categorization to support easy access / entry for new contributors - pushing this to next week, perhaps with a contributing docs update as well

Environment

  • Pydantic: 2.8

What Broke

Users experience errors when attempting to use external JSON Schema references in Pydantic models.

Why It Broke

Pydantic throws a KeyError when WithJsonSchema is used with a $ref that defines an external JSON Schema via an https link

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==1.10.18

When NOT to use: This fix should not be used if external references are not required in your schema.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/pydantic/pydantic/pull/9863

First fixed release: 1.10.18

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix should not be used if external references are not required in your schema.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.
  • Track RSS + object counts after deployments; alert on monotonic growth and GC pressure.
  • Add a long-running test that repeats the failing call path and asserts stable memory.

Version Compatibility Table

VersionStatus
1.10.18 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.