Opened 2 years ago

Closed 2 years ago

#19669 closed Bug (duplicate)

Django doesn't check type on foreign key query

Reported by: ram@… 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.

Change History (2)

comment:1 Changed 2 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

There's already a ticket for this, but I can't find it.

comment:2 Changed 2 years ago by claudep

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #16955

Note: See TracTickets for help on using tickets.
Back to Top