Skip to content
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

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

Open
pranasziaukas opened this issue Jul 11, 2023 · 0 comments
Open

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

pranasziaukas opened this issue Jul 11, 2023 · 0 comments

Comments

@pranasziaukas
Copy link
Contributor

pranasziaukas commented Jul 11, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant