#23791: Subqueries with non-"id" OneToOneField primary keys try to join against
the
wrong column name
-------------------------------------+-------------------------------------
Reporter: ris | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.7
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: orm primary_key | Unreviewed
OneToOneField subquery values | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by ris):
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> Hi, your favourite ORM obscure-query bug reporter again here...
>
> Using Django 1.7.1 & postgres, example models.py:
>
> {{{
> class ModelA ( models.Model ):
> x = models.TextField ()
>
> class ModelB ( models.Model ):
> a = models.OneToOneField ( ModelA , primary_key = True )
> }}}
>
> issuing the query
>
> {{{
> >>> ModelC.objects.filter ( pk__in = ModelC.objects.filter ( a__x = "abc"
> ) )
> }}}
>
> results in
>
> {{{
> FieldError: Cannot resolve keyword u'id' into field. Choices are: a, a_id
> }}}
>
> A workaround exists:
>
> {{{
> >>> ModelC.objects.filter ( pk__in = ModelC.objects.filter ( a__x = "abc"
> ).values ( "pk" ) )
> }}}
>
> which behaves correctly.
New description:
Hi, your favourite ORM obscure-query bug reporter again here...
Using Django 1.7.1 & postgres, example models.py:
{{{
class ModelA ( models.Model ):
x = models.TextField ()
class ModelB ( models.Model ):
a = models.OneToOneField ( ModelA , primary_key = True )
}}}
issuing the query
{{{
>>> ModelB.objects.filter ( pk__in = ModelB.objects.filter ( a__x = "abc"
) )
}}}
results in
{{{
FieldError: Cannot resolve keyword u'id' into field. Choices are: a, a_id
}}}
A workaround exists:
{{{
>>> ModelB.objects.filter ( pk__in = ModelB.objects.filter ( a__x = "abc"
).values ( "pk" ) )
}}}
which behaves correctly.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23791#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/061.024982df3074b3e1e4e112945c6cb2f9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.