Skip to content

Not all strings of length 32 or 64 are valid UUIDs #336

@pranasziaukas

Description

@pranasziaukas

def is_full_uuid(value: Any) -> bool:
"""
Return True, if the input value is a valid UUID. False otherwise.
"""
if isinstance(value, str):
if len(value) == 32 or len(value) == 62:
try:
str(value)
return True
except ValueError:
return False
return False

Not all strings of length 32 or 64 are valid UUIDs, see https://en.wikipedia.org/wiki/Universally_unique_identifier

A common way to check for the UUID validity seems to be something like

from uuid import UUID

try:
    UUID(uuid_to_test)
except ValueError:
    return False
return True

Originally posted by @pranasziaukas in #326 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions