mirror of
https://github.com/django/django.git
synced 2025-07-19 17:19:12 +00:00
[1.9.x] Fixed #26373 -- Fixed reverse lookup crash with a ForeignKey to_field in a subquery.
Backport of 4c1c93032f4a015cbb4b33958603d18ac43515b4 from master
This commit is contained in:
parent
2d178b3d2c
commit
4e8c265319
@ -1113,7 +1113,7 @@ class QuerySet(object):
|
|||||||
# if they are set up to select only a single field.
|
# if they are set up to select only a single field.
|
||||||
if len(self._fields or self.model._meta.concrete_fields) > 1:
|
if len(self._fields or self.model._meta.concrete_fields) > 1:
|
||||||
raise TypeError('Cannot use multi-field values as a filter value.')
|
raise TypeError('Cannot use multi-field values as a filter value.')
|
||||||
else:
|
elif self.model != field.model:
|
||||||
# If the query is used as a subquery for a ForeignKey with non-pk
|
# If the query is used as a subquery for a ForeignKey with non-pk
|
||||||
# target field, make sure to select the target field in the subquery.
|
# target field, make sure to select the target field in the subquery.
|
||||||
foreign_fields = getattr(field, 'foreign_related_fields', ())
|
foreign_fields = getattr(field, 'foreign_related_fields', ())
|
||||||
|
@ -30,3 +30,7 @@ Bugfixes
|
|||||||
|
|
||||||
* Fixed a regression that caused ``collectstatic --clear`` to fail if the
|
* Fixed a regression that caused ``collectstatic --clear`` to fail if the
|
||||||
storage doesn't implement ``path()`` (:ticket:`26297`).
|
storage doesn't implement ``path()`` (:ticket:`26297`).
|
||||||
|
|
||||||
|
* Fixed a crash when using a reverse lookup with a subquery when a
|
||||||
|
``ForeignKey`` has a ``to_field`` set to something other than the primary key
|
||||||
|
(:ticket:`26373`).
|
||||||
|
@ -2474,6 +2474,10 @@ class ToFieldTests(TestCase):
|
|||||||
set(Eaten.objects.filter(food__in=Food.objects.filter(name='apple').values('eaten__meal'))),
|
set(Eaten.objects.filter(food__in=Food.objects.filter(name='apple').values('eaten__meal'))),
|
||||||
set()
|
set()
|
||||||
)
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
set(Food.objects.filter(eaten__in=Eaten.objects.filter(meal='lunch'))),
|
||||||
|
{apple}
|
||||||
|
)
|
||||||
|
|
||||||
def test_reverse_in(self):
|
def test_reverse_in(self):
|
||||||
apple = Food.objects.create(name="apple")
|
apple = Food.objects.create(name="apple")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user