Skip to content

UUID validation fails when provided with 16-byte string #1541

@shawnwall

Description

@shawnwall

I'm trying to utilize fastapi + sqlalchemy which uses pydantic. My sqlalchemy column type is BINARY(16) mapping to that exact type in a MariaDB/MySQL database:

uuid = Column(BINARY(16), nullable=False, unique=True)

In pydantic I'm defining as:

uuid: UUID

I get an error thrown that the "value is not a valid uuid (type=type_error.uuid)".

I've cloned pydantic and included a new test for the following:

('uuid_check', b'\x12\x34\x56\x78' * 4, UUID('12345678-1234-5678-1234-567812345678')),

...which fails using your current code. You can find the test byte string above in the official python documentation. I've made a modification in validators to fallback to utilizing the bytes argument in UUID, and then the tests pass. I'm hoping you'd be interested in this fix, as its currently preventing us from using pydantic for a large project refactor. Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions