1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

[1.5.x] Fixed #17991 - prefetch_related fails with GenericRelation and varchar ID field

Thanks to okke@formsma.nl for the report, and carmandrew@gmail.com for the tests.

Backport of ccd14ff25b7642678bf3c9ed8a12643f04853144 from master
This commit is contained in:
Luke Plant
2012-10-29 13:40:32 +00:00
parent f427ecdc88
commit d7d7ad2881
3 changed files with 23 additions and 3 deletions

View File

@@ -319,6 +319,16 @@ class GenericRelationTests(TestCase):
for t in b.tags.all()]
self.assertEqual(sorted(tags), ["django", "python"])
def test_charfield_GFK(self):
b = Bookmark.objects.create(url='http://www.djangoproject.com/')
t1 = TaggedItem.objects.create(content_object=b, tag='django')
t2 = TaggedItem.objects.create(content_object=b, favorite=b, tag='python')
with self.assertNumQueries(3):
bookmark = Bookmark.objects.filter(pk=b.pk).prefetch_related('tags', 'favorite_tags')[0]
self.assertEqual(sorted([i.tag for i in bookmark.tags.all()]), ["django", "python"])
self.assertEqual([i.tag for i in bookmark.favorite_tags.all()], ["python"])
class MultiTableInheritanceTest(TestCase):