Skip to content

Commit

Permalink
Adding comments around serialization handling for clarity
Browse files Browse the repository at this point in the history
Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
  • Loading branch information
sydney-runkle and dmontagu committed Feb 2, 2024
1 parent 62185fa commit d1d5bcf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pydantic/functional_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ class Model(BaseModel):
func: core_schema.NoInfoValidatorFunction | core_schema.WithInfoValidatorFunction

def __get_pydantic_core_schema__(self, source_type: Any, handler: _GetCoreSchemaHandler) -> core_schema.CoreSchema:
# Note that for some valid uses of PlainValidator, it is not possible to generate a core schema for the
# source_type, so calling `handler(source_type)` will error, which prevents us from generating a proper
# serialization schema. To work around this for use cases that will not involve serialization, we simply
# catch any PydanticSchemaGenerationError that may be raised while attempting to build the serialization schema
# and abort any attempts to handle special serialization.
from pydantic import PydanticSchemaGenerationError

try:
Expand Down

0 comments on commit d1d5bcf

Please sign in to comment.