Skip to content

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

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to 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