#28175: __in query on parent model no longer works in 1.11
-------------------------------------+-------------------------------------
Reporter: Daniel Keller | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Daniel Keller:
Old description:
> I have models
>
> {{{
> class Place(models.Model):
> pass
>
> class Community(Place):
> place_ptr = models.OneToOneField(Place, parent_link=True,
> on_delete=models.CASCADE,
> primary_key=True, serialize=False, related_name='+')
>
> class Potential(models.Model):
> community = models.ForeignKey(Community, on_delete=CASCADE)
> }}}
>
> and in 1.10 I can do
> {{{
> Potential.objects.filter(community__in=Place.objects.all())
> }}}
>
> but in 1.11 this fails with
> {{{
> django.core.exceptions.FieldError: Cannot resolve keyword 'place_ptr'
> into field. Choices are: [...]
> }}}
>
> In both versions
> {{{
> Potential.objects.filter(community=Place.objects.first())
> }}}
> works fine.
>
> It's not clear to me from the docs whether the 1.10 behavior was
> intended, though.
New description:
I have models
{{{
class Place(models.Model):
pass
class Community(Place):
place_ptr = models.OneToOneField(Place, parent_link=True,
on_delete=models.CASCADE,
primary_key=True, serialize=False, related_name='+')
class Potential(models.Model):
community = models.ForeignKey(Community, on_delete=CASCADE)
}}}
and in 1.10 I can do
{{{
Potential.objects.filter(community__in=Place.objects.all())
}}}
but in 1.11 this fails with
{{{
django.core.exceptions.FieldError: Cannot resolve keyword 'place_ptr' into
field. Choices are: [...]
}}}
In both versions
{{{
Potential.objects.filter(community=Place.objects.first())
}}}
works fine.
It's not clear to me from the docs whether the 1.10 behavior was intended,
though.
It appears that adding the lines
{{{
elif getattr(self.lhs.field.target_field, 'primary_key',
False):
target_field = 'pk'
}}}
to django/db/models/fields/related_lookups.py at line 92 fixes this
problem.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/28175#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/070.d799e7e85debec20a64fc15d094bcaab%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.