﻿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
16955	Querying on the reverse of a FK with the wrong class silently returns bad data	Jeremy Dunck	David Gouldin	"{{{
class Author(Model):
    pass

class Book(Model):
    author = ForeignKey(Author, related_name='books')

class Foo(Model):
    pass

>>> a = Author.objects.create()
>>> b  = Book.objects.create(author=a)
>>> foo = Foo.objects.create(pk=999)
>>> Author.objects.filter(books=foo)
[]
}}}

I would expect this to throw an exception because a Foo is not a Book.  Instead, the Foo is coerced to its ID, which is then used as the PK for the reverse query.

This also affects ManyToManyField with through (effectively a reverse FK).

"	Bug	closed	Database layer (models, ORM)	1.3	Normal	duplicate		David Gouldin	Accepted	1	0	0	1	0	0
