Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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 jkocherhans authored
2  django/db/models/query.py
View
@@ -1402,7 +1402,7 @@ def transform_results(self, values):
# 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:
5 tests/modeltests/raw_query/models.py
View
@@ -22,4 +22,7 @@ class Coffee(models.Model):
brand = models.CharField(max_length=255, db_column="name")
class Reviewer(models.Model):
- reviewed = models.ManyToManyField(Book)
+ reviewed = models.ManyToManyField(Book)
+
+class FriendlyAuthor(Author):
+ pass
19 tests/modeltests/raw_query/tests.py
View
@@ -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 @@ def testGetItem(self):
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]
+ )
Please sign in to comment.
Something went wrong with that request. Please try again.