Skip to content

Commit 3cf9755

Browse files
committed
fix: disallow bool as input value for ULID
1 parent a257599 commit 3cf9755

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Diff for: pydantic_extra_types/ulid.py

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ def __get_pydantic_core_schema__(cls, source: type[Any], handler: GetCoreSchemaH
4747
@classmethod
4848
def _validate_ulid(cls, value: Any, handler: core_schema.ValidatorFunctionWrapHandler) -> Any:
4949
ulid: _ULID
50+
if isinstance(value, bool):
51+
raise PydanticCustomError('ulid_format', 'Unrecognized format')
5052
try:
5153
if isinstance(value, int):
5254
ulid = _ULID.from_int(value)

Diff for: tests/test_ulid.py

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class Something(BaseModel):
3737
(109667145845879622871206540411193812282, '2JG4FVY7N8XS4GFVHPXGJZ8S9T', True),
3838
(109667145845879622871206540411193812283, '2JG4FVY7N8XS4GFVHPXGJZ8S9V', True),
3939
(109667145845879622871206540411193812284, '2JG4FVY7N8XS4GFVHPXGJZ8S9W', True),
40+
# Invalid ULID for bool format
41+
(True, None, False),
42+
(False, None, False),
4043
],
4144
)
4245
def test_format_for_ulid(ulid: Any, result: Any, valid: bool):

0 commit comments

Comments
 (0)