Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…aynor.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12544 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c05de31d75970e3d5ea9ecec37e332a0f01c0fbb 1 parent 65b451a
Joseph Kocherhans authored February 23, 2010
2  django/db/models/query.py
@@ -1402,7 +1402,7 @@ def transform_results(self, values):
1402 1402
         # Construct model instance and apply annotations
1403 1403
         skip = set()
1404 1404
         for field in self.model._meta.fields:
1405  
-            if field.name not in model_init_kwargs.keys():
  1405
+            if field.attname not in model_init_kwargs.keys():
1406 1406
                 skip.add(field.attname)
1407 1407
 
1408 1408
         if skip:
5  tests/modeltests/raw_query/models.py
@@ -22,4 +22,7 @@ class Coffee(models.Model):
22 22
     brand = models.CharField(max_length=255, db_column="name")
23 23
 
24 24
 class Reviewer(models.Model):
25  
-    reviewed = models.ManyToManyField(Book)
  25
+    reviewed = models.ManyToManyField(Book)
  26
+
  27
+class FriendlyAuthor(Author):
  28
+    pass
19  tests/modeltests/raw_query/tests.py
... ...
@@ -1,7 +1,10 @@
1  
-from django.test import TestCase
2  
-from datetime import datetime
3  
-from models import Author, Book, Coffee, Reviewer
  1
+from datetime import date
  2
+
4 3
 from django.db.models.sql.query import InvalidQuery
  4
+from django.test import TestCase
  5
+
  6
+from models import Author, Book, Coffee, Reviewer, FriendlyAuthor
  7
+
5 8
 
6 9
 class RawQueryTests(TestCase):
7 10
 
@@ -197,3 +200,13 @@ def testGetItem(self):
197 200
         self.assertEquals(len(first_two), 2)
198 201
 
199 202
         self.assertRaises(TypeError, lambda: Author.objects.raw(query)['test'])
  203
+
  204
+    def test_inheritance(self):
  205
+        # date is the end of the Cuban Missile Crisis, I have no idea when
  206
+        # Wesley was bron
  207
+        f = FriendlyAuthor.objects.create(first_name="Wesley", last_name="Chun",
  208
+            dob=date(1962, 10, 28))
  209
+        query = "SELECT * FROM raw_query_friendlyauthor"
  210
+        self.assertEqual(
  211
+            [o.pk for o in FriendlyAuthor.objects.raw(query)], [f.pk]
  212
+        )

0 notes on commit c05de31

Please sign in to comment.
Something went wrong with that request. Please try again.