summaryrefslogtreecommitdiff
path: root/tests/foreign_object
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2025-04-02 13:32:38 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2025-04-03 22:20:50 +0200
commit8ebdd37a0b1755842baae3bd34d388156ad4bf53 (patch)
tree3433e0ea9965d65905b7353b6783657add9e9185 /tests/foreign_object
parent317690403a40fbaf52c6abcbc8d39f199c9b5102 (diff)
[5.2.x] Fixed #36290 -- Made TupleIn() lookup discard tuples containing None.
Just like the In() lookup discards of None members TupleIn() should discard tuples containing any None as NULL != NULL in SQL and the framework expects such queries to be elided under some circumstances. Refs #31667, #36116. Thanks Basptise Mispelon for bisecting the regression to 626d77e. Backport of f7f38f3a0b44d8c6d14344dae66b6ce52cd77b55 from main
Diffstat (limited to 'tests/foreign_object')
-rw-r--r--tests/foreign_object/models/person.py2
-rw-r--r--tests/foreign_object/tests.py13
2 files changed, 14 insertions, 1 deletions
diff --git a/tests/foreign_object/models/person.py b/tests/foreign_object/models/person.py
index d536ab63d7..4290ad6d3b 100644
--- a/tests/foreign_object/models/person.py
+++ b/tests/foreign_object/models/person.py
@@ -84,7 +84,7 @@ class Friendship(models.Model):
)
from_friend_id = models.IntegerField()
to_friend_country_id = models.IntegerField()
- to_friend_id = models.IntegerField()
+ to_friend_id = models.IntegerField(null=True)
# Relation Fields
from_friend = models.ForeignObject(
diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py
index 8b36df29d7..0bba0eaa98 100644
--- a/tests/foreign_object/tests.py
+++ b/tests/foreign_object/tests.py
@@ -297,6 +297,19 @@ class MultiColumnFKTests(TestCase):
self.assertEqual(friendships[0].to_friend, self.george)
self.assertEqual(friendships[1].to_friend, self.sam)
+ def test_prefetch_foreignobject_null_hidden_forward_skipped(self):
+ fiendship = Friendship.objects.create(
+ from_friend_country=self.usa,
+ from_friend_id=self.bob.id,
+ to_friend_country_id=self.usa.id,
+ to_friend_id=None,
+ )
+ with self.assertNumQueries(1):
+ self.assertEqual(
+ Friendship.objects.prefetch_related("to_friend").get(),
+ fiendship,
+ )
+
def test_prefetch_foreignobject_reverse(self):
Membership.objects.create(
membership_country=self.usa, person=self.bob, group=self.cia