Skip to content

fix: disallow bool as input value for ULID #305

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

Merged
merged 1 commit into from
Apr 2, 2025
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