1
0
mirror of https://github.com/django/django.git synced 2025-10-27 07:36:08 +00:00

[1.8.x] Fixed #12768 -- Fixed QuerySet.raw() regression on FK with custom db_column.

Backport of e063ac2fae from master
This commit is contained in:
Matt Johnson
2015-07-22 11:54:42 -07:00
committed by Tim Graham
parent ca13fb021f
commit 05c7129bf2
4 changed files with 24 additions and 4 deletions

View File

@@ -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):
@@ -259,3 +259,15 @@ 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.
"""
b1 = Book.objects.latest('id')
b = BookFkAsPk.objects.create(book=b1)
self.assertEqual(list(BookFkAsPk.objects.raw('SELECT not_the_default FROM raw_query_bookfkaspk')), [b])