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

fix prefetch related with UUID fields

Open berndtj opened this issue 10 years ago • 3 comments

Because the foreign key is stored as a string (char field) and the uuid field is returned as a UUID (StringUUID) object, prefetch related does not work.

This patch makes StringUUID dict keys equivelent to string dict keys.

berndtj avatar Jul 09 '14 20:07 berndtj

This fixes the prefetch related issue and does not break existing code since the .hex method can still be called on the StringUUID object.

berndtj avatar Jul 09 '14 20:07 berndtj

Looks good to me. Any concerns, @dcramer?

luto avatar Nov 05 '14 08:11 luto

The fix is not working when you are using hyphen = True in your model. In this case in the dictionary it will be UUID with hyphen and checked against hex format what is incorrect. IMHO you should __hash__ and __eq__ do against hex values always to be determenistic

sshishov avatar Feb 24 '21 08:02 sshishov