Skip to content

Commit

Permalink
Add caches for collecting definitions and invalid schemas from a Core…
Browse files Browse the repository at this point in the history
…Schema (#7527)
  • Loading branch information
adriangb committed Sep 20, 2023
1 parent 56f41a4 commit 2d36952
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pydantic/_internal/_core_utils.py
Expand Up @@ -116,6 +116,12 @@ def collect_definitions(schema: core_schema.CoreSchema) -> dict[str, core_schema
defs: dict[str, CoreSchema] = {}

def _record_valid_refs(s: core_schema.CoreSchema, recurse: Recurse) -> core_schema.CoreSchema:
if 'metadata' in s:
definitions_cache: _DefinitionsState | None = s['metadata'].get(_DEFINITIONS_CACHE_METADATA_KEY, None)
if definitions_cache is not None:
defs.update(definitions_cache['definitions'])
return s

ref = get_ref(s)
if ref:
defs[ref] = s
Expand Down

0 comments on commit 2d36952

Please sign in to comment.