django-uuidfield
django-uuidfield copied to clipboard
Inconsistent backend UUID values in method get_db_prep_value()
Besides #46, another issue with method get_db_prep_value
is inconsistency of hyphens.
Let's say we pass the value as a UUID object UUID('00010203-0405-0607-0809-0a0b0c0d0e0f')
. The method returns str(value)
, which, according to Python doc, is stringified with hyphen '00010203-0405-0607-0809-0a0b0c0d0e0f'
. However, if we pass a string '00010203-0405-0607-0809-0a0b0c0d0e0f'
, the method will return a non-hyphen version of it. It doesn't matter with PostgreSQL which supports UUID type, but for other backends where UUID is stored as a char32
the inconsistency would be a problem.
But if the field is nullable won't this return existing objects with a null UUID when using an anvalid UUID in lookup?
@ksonbol That's right -- I didn't consider the null=True
situation...
Thus it seems returning an arbitrary UUID is the only way to work around this problem?
@ksonbol It seems that UUIDField is designed to be an auto field... https://github.com/dcramer/django-uuidfield/blob/master/uuidfield/tests/tests.py#L19-L20