Opened 3 days ago
Last modified 3 days ago
#35928 closed Bug
[contenttypes] GenericRelation uses wrong primary key type if set to models.UUIDField — at Version 1
Reported by: | Jon Eyolfson | Owned by: | |
---|---|---|---|
Component: | contrib.contenttypes | Version: | 5.1 |
Severity: | Normal | Keywords: | GenericRelation, UUIDField |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
For a minimal example, if I have the following:
class Delivery(models.Model): id = models.UUIDField(primary_key=True, editable=False) content_type = models.ForeignKey( ContentType, on_delete=models.CASCADE, null=True, blank=True, editable=False, ) object_id = models.PositiveBigIntegerField( blank=True, null=True, editable=False, ) content_object = GenericForeignKey("content_type", "object_id") class Other(models.Model): delivery = GenericRelation(Delivery, related_query_name="other")
If I use delivery.other.all().query
I see the wrong primary key:
SELECT /* SNIP */ WHERE "delivery"."id" = 269290806699601176541887178676879701060
If I look at a normal query with the primary key on Delivery, like Delivery.objects.filter(pk=delivery_pk).query
, I see:
SELECT /* SNIP */ WHERE "delivery"."id" = ca9785d8a6e311ef874b0ad61d0b3444
This causes SQLite to show the following error:
OverflowError: Python int too large to convert to SQLite INTEGER
I assume because GenericRelation is converting the UUID to an integer, which would cause the lookup to fail anyways.
Note:
See TracTickets
for help on using tickets.