Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ByteSize error type change #8681

Merged
merged 4 commits into from Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion pydantic/types.py
Expand Up @@ -1787,7 +1787,9 @@ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaH
[
core_schema.str_schema(pattern=cls.byte_string_pattern),
core_schema.int_schema(ge=0),
]
],
custom_error_type='byte_size',
custom_error_message='could not parse value and unit from byte string',
),
serialization=core_schema.plain_serializer_function_ser_schema(
int, return_schema=core_schema.int_schema(ge=0)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_types.py
Expand Up @@ -4481,7 +4481,7 @@ def test_bytesize_raises():
class Model(BaseModel):
size: ByteSize

with pytest.raises(ValidationError, match='should match'):
with pytest.raises(ValidationError, match='parse value'):
Model(size='d1MB')
dmontagu marked this conversation as resolved.
Show resolved Hide resolved

with pytest.raises(ValidationError, match='byte unit'):
Expand Down