Skip to content

Commit

Permalink
delegate UUID serialization to pydantic-core (#6850)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Jul 25, 2023
1 parent cff5385 commit 3c02267
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
14 changes: 1 addition & 13 deletions pydantic/_internal/_std_types_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,19 +373,7 @@ def uuid_prepare_pydantic_annotations(
if source_type is not UUID:
return None

schema = core_schema.uuid_schema(
# TODO: this shouldn't be necessary, but avoids a UserWarning emitted
# when serializing a string
serialization=core_schema.to_string_ser_schema(),
)

return (
source_type,
[
InnerSchemaValidator(schema, js_core_schema=core_schema.str_schema(), js_schema_update={'format': 'uuid'}),
*annotations,
],
)
return (source_type, [InnerSchemaValidator(core_schema.uuid_schema()), *annotations])


def path_schema_prepare_pydantic_annotations(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MyModel(BaseModel):
@pytest.mark.parametrize(
'ser_type,gen_value,json_output',
[
(UUID, lambda: 'ebcdab58-6eb8-46fb-a190-d07a33e9eac8', b'"ebcdab58-6eb8-46fb-a190-d07a33e9eac8"'),
(UUID, lambda: UUID('ebcdab58-6eb8-46fb-a190-d07a33e9eac8'), b'"ebcdab58-6eb8-46fb-a190-d07a33e9eac8"'),
(IPv4Address, lambda: '192.168.0.1', b'"192.168.0.1"'),
(Color, lambda: Color('#000'), b'"black"'),
(Color, lambda: Color((1, 12, 123)), b'"#010c7b"'),
Expand Down

0 comments on commit 3c02267

Please sign in to comment.