dcramer / django-uuidfield

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

Inconsistent backend UUID values in method get_db_prep_value() #49

Open lingxiaoyang opened 9 years ago

lingxiaoyang commented 9 years ago

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.

ksonbol commented 9 years ago

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

lingxiaoyang commented 9 years ago

@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 commented 9 years ago

@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