summaryrefslogtreecommitdiff
path: root/tests/raw_query/tests.py
diff options
context:
space:
mode:
authorMatt Johnson <mdj2@pdx.edu>2015-07-22 11:54:42 -0700
committerTim Graham <timograham@gmail.com>2015-07-23 18:07:38 -0400
commite063ac2fae007a2eecaeab5ce17064c31230ce29 (patch)
tree981151d26d168b54bdef160b2c97a5bc7072ace3 /tests/raw_query/tests.py
parent71df9b7de4bcb760e756d119685636e101898816 (diff)
Fixed #12768 -- Fixed QuerySet.raw() regression on FK with custom db_column.
Diffstat (limited to 'tests/raw_query/tests.py')
-rw-r--r--tests/raw_query/tests.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/tests/raw_query/tests.py b/tests/raw_query/tests.py
index 2027a32d2b..94f21f9a71 100644
--- a/tests/raw_query/tests.py
+++ b/tests/raw_query/tests.py
@@ -5,7 +5,7 @@ from datetime import date
from django.db.models.query_utils import InvalidQuery
from django.test import TestCase, skipUnlessDBFeature
-from .models import Author, Book, Coffee, FriendlyAuthor, Reviewer
+from .models import Author, Book, BookFkAsPk, Coffee, FriendlyAuthor, Reviewer
class RawQueryTests(TestCase):
@@ -274,3 +274,14 @@ class RawQueryTests(TestCase):
list(Book.objects.raw('SELECT id FROM (SELECT * FROM raw_query_book WHERE paperback IS NOT NULL) sq'))
except InvalidQuery:
self.fail("Using a subquery in a RawQuerySet raised InvalidQuery")
+
+ def test_db_column_name_is_used_in_raw_query(self):
+ """
+ Regression test that ensures the `column` attribute on the field is
+ used to generate the list of fields included in the query, as opposed
+ to the `attname`. This is important when the primary key is a
+ ForeignKey field because `attname` and `column` are not necessarily the
+ same.
+ """
+ b = BookFkAsPk.objects.create(book=self.b1)
+ self.assertEqual(list(BookFkAsPk.objects.raw('SELECT not_the_default FROM raw_query_bookfkaspk')), [b])