django-uuidfield icon indicating copy to clipboard operation
django-uuidfield copied to clipboard

Inconsistent backend UUID values in method get_db_prep_value()

Open lingxiaoyang opened this issue 10 years ago • 3 comments

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.

lingxiaoyang avatar Dec 10 '14 14:12 lingxiaoyang

But if the field is nullable won't this return existing objects with a null UUID when using an anvalid UUID in lookup?

ksonbol avatar Dec 10 '14 16:12 ksonbol

@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?

lingxiaoyang avatar Dec 10 '14 16:12 lingxiaoyang

@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

lingxiaoyang avatar Dec 10 '14 16:12 lingxiaoyang