#26667: Invalid query for OneToOneField if 'to_field' specified and
primary_key=True
-------------------------------------+-------------------------------------
Reporter: kwist | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.9
(models, ORM) |
Severity: Normal | Resolution:
Keywords: OneToOneField | Triage Stage:
to_field primary_key | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by kwist):
* needs_docs: => 0
* needs_tests: => 0
* needs_better_patch: => 0
Old description:
> Given the following models:
> {{{
> #!python
> 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:
> {{{
> #!python
> Model2.objects.filter(model1=instance_model1)
> }}}
> always returns an empty list, though in Django 1.8 works
>
> Django 1.9 query
> {{{
> #!python
> In [4]: print Model2.objects.filter(model1=model1).query
> SELECT "app_model2"."model1_id" FROM "app_model2" WHERE
> "app_model2"."model1_id" = 1
> }}}
>
> Django 1.8 query
> {{{
> #!python
> In [4]: print Model2.objects.filter(model1=model1).query
> SELECT `app_model2`.`model1_id` FROM `app_model2` WHERE
> `app_model2`.`model1_id` = 1234567890ax
> }}}
New description:
Given the following models:
{{{
#!python
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:
{{{
#!python
Model2.objects.filter(model1=instance_model1)
}}}
always returns an empty list, though in Django 1.8 works
Django 1.9 query
{{{
#!python
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
{{{
#!python
In [4]: print Model2.objects.filter(model1=instance_model1).query
SELECT `app_model2`.`model1_id` FROM `app_model2` WHERE
`app_model2`.`model1_id` = 1234567890ax
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26667#comment:1>
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/063.7afba6959f22fb532f4585e62b6b29ab%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.