django-uuidfield
django-uuidfield copied to clipboard
fix prefetch related with UUID fields
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.
This fixes the prefetch related issue and does not break existing code since the .hex method can still be called on the StringUUID object.
Looks good to me. Any concerns, @dcramer?
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