Set the LOGFIRE_PYDANTIC_RECORD environment variable to "off" to disable the plugin, or
PYDANTIC_DISABLE_PLUGINS to true to disable all Pydantic plugins.
A tuple of decorator factories for each of the three validation methods -
validate_python, validate_json, validate_strings or a tuple of
three None if recording is off.
defnew_schema_validator(self,schema:CoreSchema,schema_type:Any,schema_type_path:SchemaTypePath,schema_kind:SchemaKind,config:CoreConfig|None,plugin_settings:dict[str,Any],)->tuple[_ValidateWrapper,...]|tuple[None,...]:"""This method is called every time a new `SchemaValidator` is created. Args: schema: The schema to validate against. schema_type: The original type which the schema was created from, e.g. the model class. schema_type_path: Path defining where `schema_type` was defined, or where `TypeAdapter` was called. schema_kind: The kind of schema to validate against. config: The config to use for validation. plugin_settings: The plugin settings. Returns: A tuple of decorator factories for each of the three validation methods - `validate_python`, `validate_json`, `validate_strings` or a tuple of three `None` if recording is `off`. """# Patch a bug that occurs even if the plugin is disabled._patch_PluggableSchemaValidator()logfire_settings=plugin_settings.get('logfire')iflogfire_settingsand'record'inlogfire_settings:record=logfire_settings['record']else:record=get_pydantic_plugin_config().recordifrecord=='off':returnNone,None,Noneif_include_model(schema_type_path):_patch_build_wrapper()return(_ValidateWrapper('validate_python',schema,config,plugin_settings,schema_type_path,record),_ValidateWrapper('validate_json',schema,config,plugin_settings,schema_type_path,record),_ValidateWrapper('validate_strings',schema,config,plugin_settings,schema_type_path,record),)returnNone,None,None
The follow rules are used:
* If the schema represents a model or dataclass, use the name of the class.
* If the root schema is a wrap/before/after validator, look at its schema property.
* Otherwise use the schema's type property.
defget_schema_name(schema:CoreSchema)->str:"""Find the best name to use for a schema. The follow rules are used: * If the schema represents a model or dataclass, use the name of the class. * If the root schema is a wrap/before/after validator, look at its `schema` property. * Otherwise use the schema's `type` property. Args: schema: The schema to get the name for. Returns: The name of the schema. """ifschema['type']in{'model','dataclass'}:returnschema['cls'].__name__# type: ignoreelifschema['type']in{'function-after','function-before','function-wrap'}:returnget_schema_name(schema['schema'])# type: ignoreelifschema['type']=='definitions':inner_schema=schema['schema']ifinner_schema['type']=='definition-ref':schema_ref:str=inner_schema['schema_ref']# type: ignore[schema_definition]=[definitionfordefinitioninschema['definitions']ifdefinition['ref']==schema_ref# type: ignore]returnget_schema_name(schema_definition)else:returnget_schema_name(inner_schema)else:returnschema['type']
defget_pydantic_plugin_config()->PydanticPlugin:"""Get the Pydantic plugin config."""if_pydantic_plugin_config_valueisnotNone:return_pydantic_plugin_config_valueelse:returnGLOBAL_CONFIG.param_manager.pydantic_plugin
defset_pydantic_plugin_config(plugin_config:PydanticPlugin|None)->None:"""Set the pydantic plugin config."""global_pydantic_plugin_config_value_pydantic_plugin_config_value=plugin_config