Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pydantic_extra_types/ulid.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaH
@classmethod
def _validate_ulid(cls, value: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> Any:
ulid: _ULID
if isinstance(value, bool):
raise PydanticCustomError('ulid_format', 'Unrecognized format')
try:
if isinstance(value, int):
ulid = _ULID.from_int(value)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_ulid.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class Something(BaseModel):
(109667145845879622871206540411193812282, '2JG4FVY7N8XS4GFVHPXGJZ8S9T', True),
(109667145845879622871206540411193812283, '2JG4FVY7N8XS4GFVHPXGJZ8S9V', True),
(109667145845879622871206540411193812284, '2JG4FVY7N8XS4GFVHPXGJZ8S9W', True),
# Invalid ULID for bool format
(True, None, False),
(False, None, False),
],
)
def test_format_for_ulid(ulid: Any, result: Any, valid: bool):
Expand Down