#26667 closed Bug (fixed)
Invalid query for OneToOneField if 'to_field' specified and primary_key=True
Reported by: | Vitaliy Yelnik | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.9 |
Severity: | Release blocker | Keywords: | OneToOneField to_field primary_key |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Given the following models:
class Model1(models.Model): str_id = models.CharField(max_length=12, unique=True) class Model2(models.Model): model1 = models.OneToOneField(Model1, to_field='str_id', primary_key=True)
In Django 1.9 query:
Model2.objects.filter(model1=instance_model1)
always returns an empty list, though in Django 1.8 works
Django 1.9 query
In [4]: print Model2.objects.filter(model1=instance_model1).query SELECT "app_model2"."model1_id" FROM "app_model2" WHERE "app_model2"."model1_id" = 1
Django 1.8 query
In [4]: print Model2.objects.filter(model1=instance_model1).query SELECT `app_model2`.`model1_id` FROM `app_model2` WHERE `app_model2`.`model1_id` = 1234567890ax
Attachments (1)
Change History (7)
comment:1 by , 9 years ago
Description: | modified (diff) |
---|
comment:2 by , 9 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
Note:
See TracTickets
for help on using tickets.
Bisected to 9ed82154bd0bd01c6195942db84302e791ad366f.