Django doesn't check type on foreign key query
|Reported by:||ram@…||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.4|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I can only test on 1.4.x and not 1.5.x, so if someone can test on 1.5.x that would help. (If the bug was already found and fixed in 1.5.x I'll be happy!)
If you're making a lookup that includes a foreign-key field, and you pass in an object of a different type, Django doesn't complain but just uses the ID of the object you put in even if it's of a different type.
If you pass in a Site object instead of a User object, Django will not raise an exception, but will look for a Chair whose User has an ID equal to that of site, which is probably never what the user wants and caused a hard-to-find bug for me in my application.
I suggest simply raising an exception in this case.