#30343: Prefetch related is not working when used GFK for model that uses UUID
field as PK.
-------------------------------------+-------------------------------------
Reporter: timur-orudzhov | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: prefetch_related, | Triage Stage: Accepted
UUID, generic foreign key |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by felixxm):
IMO, adding `get_prep_value()` to the `UUIDField` should fix this issue
🤔:
{{{
diff --git a/django/db/models/fields/__init__.py
b/django/db/models/fields/__init__.py
index 2307dcae25..0a7a6b9736 100644
--- a/django/db/models/fields/__init__.py
+++ b/django/db/models/fields/__init__.py
@@ -2335,6 +2335,12 @@ class UUIDField(Field):
return value
return value.hex
+ def get_prep_value(self, value):
+ value = super().get_prep_value(value)
+ if value is None:
+ return None
+ return self.to_python(value)
+
def to_python(self, value):
if value is not None and not isinstance(value, uuid.UUID):
input_form = 'int' if isinstance(value, int) else 'hex'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30343#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/072.346846c5527f9e54b1fbdf499c65374c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.