From 34ba86706f0db33d9a0ab44e4abb78703e7262a9 Mon Sep 17 00:00:00 2001 From: Anubhav Joshi Date: Sat, 14 Jun 2014 12:54:19 +0530 Subject: Fixed #14334 -- Query relation lookups now check object types. Thanks rpbarlow for the suggestion; and loic, akaariai, and jorgecarleitao for reviews. --- docs/releases/1.8.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'docs') diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index 7534a16e3d..793c781e2f 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -350,6 +350,21 @@ The check also applies to the columns generated in an implicit and then specify :attr:`~django.db.models.Field.db_column` on its column(s) as needed. +Query relation lookups now check object types +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Querying for model lookups now checks if the object passed is of correct type +and raises a :exc:`ValueError` if not. Previously, Django didn't care if the +object was of correct type; it just used the object's related field attribute +(e.g. ``id``) for the lookup. Now, an error is raised to prevent incorrect +lookups:: + + >>> book = Book.objects.create(name="Django") + >>> book = Book.objects.filter(author=book) + Traceback (most recent call last): + ... + ValueError: Cannot query "": Must be "Author" instance. + Miscellaneous ~~~~~~~~~~~~~ -- cgit v1.3