Opened 12 years ago
Closed 12 years ago
#19669 closed Bug (duplicate)
Django doesn't check type on foreign key query
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.4 |
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
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.
Example:
Chair.objects.filter(user=site)
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.
There's already a ticket for this, but I can't find it.