﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22876	Related lookups allow models of a different type	Ben Davis	nobody	"Django currently allows this:

{{{
#!python
>>> pig = Pig.objects.get(pk=1)
>>> duck = Duck.objects.get(pk=1)
>>> ducklings = Duckling.objects.filter(mother_duck=pig)
[<Duckling: Duckling object>, <Duckling: Duckling object>]
}}}

Unfortunately this can lead to baby ducklings being adopted by pigs.

A commit was made last year that was intended to fix this ( changeset:7cca8d5 ), but the test doesn't seem to be written correctly. It should assert that the resulting queryset is ''empty'', not populated with `ob`:

{{{
#!diff
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index 60d1083..cb615bb 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -3247,10 +3247,16 @@ class RelatedLookupTypeTests(TestCase):
         # be a good idea...
         self.assertQuerysetEqual(
             ObjectB.objects.filter(objecta=wrong_type),
-            [ob], lambda x: x)
+            [], lambda x: x)
         self.assertQuerysetEqual(
             ObjectB.objects.filter(objecta__in=[wrong_type]),
-            [ob], lambda x: x)
+            [], lambda x: x)
}}}"	Bug	closed	Database layer (models, ORM)	dev	Normal	duplicate			Unreviewed	0	0	0	0	0	0
