Opened 11 years ago
Closed 11 years ago
#22876 closed Bug (duplicate)
Related lookups allow models of a different type
Reported by: | Ben Davis | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django currently allows this:
>>> 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
:
-
tests/queries/tests.py
diff --git a/tests/queries/tests.py b/tests/queries/tests.py index 60d1083..cb615bb 100644
a b class RelatedLookupTypeTests(TestCase): 3247 3247 # be a good idea... 3248 3248 self.assertQuerysetEqual( 3249 3249 ObjectB.objects.filter(objecta=wrong_type), 3250 [ ob], lambda x: x)3250 [], lambda x: x) 3251 3251 self.assertQuerysetEqual( 3252 3252 ObjectB.objects.filter(objecta__in=[wrong_type]), 3253 [ ob], lambda x: x)3253 [], lambda x: x)
Change History (2)
comment:1 by , 11 years ago
comment:2 by , 11 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Yep, the proposed patch there fixes the issue. Closing.
Note:
See TracTickets
for help on using tickets.
Duplicate of #14334, I think.