dcramer / django-uuidfield

A UUIDField for Django
BSD 3-Clause "New" or "Revised" License
262 stars 115 forks source link

Raise ValueError in get_db_prep_value() when value is of invalid length #48

Closed ksonbol closed 9 years ago

ksonbol commented 9 years ago

Fixes #46.

rychlis commented 9 years ago

+1

rychlis commented 9 years ago

IMO a better approach would be to attempt to create an uuid.UUID instance which would raise exceptions automatically. All the checks are already present in the UUID class so there is no need to replicate these in the UUIDField. This also solves many other cases like non-hex characters in the string.

...
uuid.UUID(value) # This will raise TypeError or ValueError for bad values
return value
ksonbol commented 9 years ago

@rychlis Great idea! I will add this to the pull request.

dcramer commented 9 years ago

Thanks all!