Fixed #12731. Fixed a bug with .raw() and inheritance. Thanks, Alex Gaynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12544 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Joseph Kocherhans 2010-02-23 19:39:06 +00:00
parent 65b451ae3e
commit c05de31d75
3 changed files with 21 additions and 5 deletions

View File

@ -1402,7 +1402,7 @@ class RawQuerySet(object):
# Construct model instance and apply annotations
skip = set()
for field in self.model._meta.fields:
if field.name not in model_init_kwargs.keys():
if field.attname not in model_init_kwargs.keys():
skip.add(field.attname)
if skip:

View File

@ -23,3 +23,6 @@ class Coffee(models.Model):
class Reviewer(models.Model):
reviewed = models.ManyToManyField(Book)
class FriendlyAuthor(Author):
pass

View File

@ -1,7 +1,10 @@
from django.test import TestCase
from datetime import datetime
from models import Author, Book, Coffee, Reviewer
from datetime import date
from django.db.models.sql.query import InvalidQuery
from django.test import TestCase
from models import Author, Book, Coffee, Reviewer, FriendlyAuthor
class RawQueryTests(TestCase):
@ -197,3 +200,13 @@ class RawQueryTests(TestCase):
self.assertEquals(len(first_two), 2)
self.assertRaises(TypeError, lambda: Author.objects.raw(query)['test'])
def test_inheritance(self):
# date is the end of the Cuban Missile Crisis, I have no idea when
# Wesley was bron
f = FriendlyAuthor.objects.create(first_name="Wesley", last_name="Chun",
dob=date(1962, 10, 28))
query = "SELECT * FROM raw_query_friendlyauthor"
self.assertEqual(
[o.pk for o in FriendlyAuthor.objects.raw(query)], [f.pk]
)