summaryrefslogtreecommitdiff
path: root/tests/one_to_one
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2015-06-25 18:31:07 +0300
committerTim Graham <timograham@gmail.com>2015-06-29 07:49:31 -0400
commit9ed82154bd0bd01c6195942db84302e791ad366f (patch)
tree13e1a31125e71859646e58f9b6c8bb589b1911bd /tests/one_to_one
parent736fb1838cc25f5faf57cd2a4f6b6ab32ff9aadc (diff)
downloaddjango-9ed82154bd0bd01c6195942db84302e791ad366f.tar.gz
Fixed #23791 -- Corrected object type check for pk__in=qs
When the pk was a relation field, qs.filter(pk__in=qs) didn't work. In addition, fixed Restaurant.objects.filter(place=restaurant_instance), where place is an OneToOneField and the primary key of Restaurant. A big thank you to Josh for review and to Tim for review and cosmetic edits. Thanks to Beauhurst for commissioning the work on this ticket.
Diffstat (limited to 'tests/one_to_one')
-rw-r--r--tests/one_to_one/tests.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/one_to_one/tests.py b/tests/one_to_one/tests.py
index 6604299076..041fe6857c 100644
--- a/tests/one_to_one/tests.py
+++ b/tests/one_to_one/tests.py
@@ -479,3 +479,21 @@ class OneToOneTests(TestCase):
Waiter.objects.update(restaurant=r2)
w.refresh_from_db()
self.assertEqual(w.restaurant, r2)
+
+ def test_rel_pk_subquery(self):
+ r = Restaurant.objects.first()
+ q1 = Restaurant.objects.filter(place_id=r.pk)
+ # Test that subquery using primary key and a query against the
+ # same model works correctly.
+ q2 = Restaurant.objects.filter(place_id__in=q1)
+ self.assertQuerysetEqual(q2, [r], lambda x: x)
+ # Test that subquery using 'pk__in' instead of 'place_id__in' work, too.
+ q2 = Restaurant.objects.filter(
+ pk__in=Restaurant.objects.filter(place__id=r.place.pk)
+ )
+ self.assertQuerysetEqual(q2, [r], lambda x: x)
+
+ def test_rel_pk_exact(self):
+ r = Restaurant.objects.first()
+ r2 = Restaurant.objects.filter(pk__exact=r).first()
+ self.assertEqual(r, r2)