@@ -92,58 +92,6 @@ def _validated_schema(canonical_schema: bytes) -> Draft202012Validator:
9292 return Draft202012Validator (normalized , format_checker = FormatChecker ())
9393
9494
95- @lru_cache (maxsize = 1024 )
96- def _trusted_validated_schema (canonical_schema : bytes ) -> Draft202012Validator :
97- """Compile a schema without re-validating against the meta-schema.
98-
99- Pydantic's model_json_schema() produces valid Draft 2020-12 schemas
100- by construction. Skipping the expensive meta-schema walk for those
101- schemas eliminates the dominant cost of runtime construction (~6.7s
102- across 527 unique schemas at ~12.7ms each). External references are
103- still rejected; only the meta-schema check is skipped.
104- """
105-
106- normalized = loads_strict_json (canonical_schema )
107- _reject_external_references (normalized )
108- return Draft202012Validator (normalized , format_checker = FormatChecker ())
109-
110-
111- def _uses_operator_owned_pydantic_schema (model : type [BaseModel ]) -> bool :
112- """Return whether Pydantic owns the complete model schema generation path."""
113-
114- model_schema_method = getattr (model .model_json_schema , "__func__" , None )
115- base_schema_method = getattr (BaseModel .model_json_schema , "__func__" , None )
116- model_schema_hook = getattr (model .__get_pydantic_json_schema__ , "__func__" , None )
117- base_schema_hook = getattr (BaseModel .__get_pydantic_json_schema__ , "__func__" , None )
118- return (
119- model .__module__ .startswith ("jacobian." )
120- and model_schema_method is base_schema_method
121- and model_schema_hook is base_schema_hook
122- and model .model_config .get ("json_schema_extra" ) is None
123- and _core_schema_uses_only_pydantic_defaults (model .__pydantic_core_schema__ )
124- )
125-
126-
127- def _core_schema_uses_only_pydantic_defaults (value : Any ) -> bool :
128- if isinstance (value , list | tuple ):
129- return all (_core_schema_uses_only_pydantic_defaults (item ) for item in value )
130- if not isinstance (value , dict ):
131- return True
132- if value .get ("pydantic_js_extra" ) is not None or value .get (
133- "pydantic_js_annotation_functions"
134- ):
135- return False
136- base_schema_hook = getattr (BaseModel .__get_pydantic_json_schema__ , "__func__" , None )
137- for hook in value .get ("pydantic_js_functions" , ()):
138- function = getattr (hook , "__func__" , hook )
139- module = getattr (function , "__module__" , "" )
140- if function is not base_schema_hook and not module .startswith ("pydantic." ):
141- return False
142- return all (
143- _core_schema_uses_only_pydantic_defaults (item ) for item in value .values ()
144- )
145-
146-
14795class SchemaRegistry :
14896 """Store and apply closed local JSON Schemas used by artifact contracts."""
14997
@@ -164,23 +112,6 @@ def register(
164112 ) -> str :
165113 """Register a schema after rejecting unsupported external references."""
166114
167- return self ._register (
168- name = name ,
169- version = version ,
170- schema = schema ,
171- skip_meta_validation = False ,
172- )
173-
174- def _register (
175- self ,
176- * ,
177- name : str ,
178- version : str ,
179- schema : dict [str , Any ],
180- skip_meta_validation : bool ,
181- ) -> str :
182- """Register one schema under an internally established trust policy."""
183-
184115 self ._reconcile_pending ()
185116 canonical_schema = canonicalize_json (schema )
186117 registration = (name , version , canonical_schema )
@@ -207,10 +138,7 @@ def _register(
207138 version = version ,
208139 definition = schema ,
209140 )
210- if skip_meta_validation :
211- _trusted_validated_schema (canonical_schema )
212- else :
213- _validated_schema (canonical_schema )
141+ _validated_schema (canonical_schema )
214142 schema_uri = self .store .register_descriptor (
215143 kind = "schema" ,
216144 name = name ,
@@ -242,12 +170,10 @@ def register_model(
242170 repeats this registration after every restart before accepting writes.
243171 """
244172
245- schema = model_schema (model )
246- schema_uri = self ._register (
173+ schema_uri = self .register (
247174 name = name ,
248175 version = version ,
249- schema = schema ,
250- skip_meta_validation = _uses_operator_owned_pydantic_schema (model ),
176+ schema = model_schema (model ),
251177 )
252178 self ._bind_model_contract (schema_uri , model )
253179 if producer_only :
0 commit comments