diff --git a/pydantic_extra_types/ulid.py b/pydantic_extra_types/ulid.py index 814e050..ae02f5a 100644 --- a/pydantic_extra_types/ulid.py +++ b/pydantic_extra_types/ulid.py @@ -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) diff --git a/tests/test_ulid.py b/tests/test_ulid.py index 94cec2d..7b8b129 100644 --- a/tests/test_ulid.py +++ b/tests/test_ulid.py @@ -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):