Skip to content

Instantly share code, notes, and snippets.

@loic
Last active August 29, 2015 13:58
Show Gist options
  • Save loic/10345520 to your computer and use it in GitHub Desktop.
Save loic/10345520 to your computer and use it in GitHub Desktop.
index 1bb64c9..253f382 100644
--- a/tests/prefetch_related/tests.py
+++ b/tests/prefetch_related/tests.py
@@ -4,8 +4,10 @@ from django.core.exceptions import ObjectDoesNotExist
from django.contrib.contenttypes.models import ContentType
from django.db import connection
from django.db.models import Prefetch
+from django.db.models.query import get_prefetcher
from django.test import TestCase, override_settings
from django.utils import six
+from django.utils.encoding import force_text
from .models import (Author, Book, Reader, Qualification, Teacher, Department,
TaggedItem, Bookmark, AuthorAddress, FavoriteAuthors, AuthorWithAge,
@@ -1055,3 +1057,19 @@ class Ticket21410Tests(TestCase):
def test_bug(self):
list(Author2.objects.prefetch_related('first_book', 'favorite_books'))
+
+
+class Ticket21760Tests(TestCase):
+
+ def setUp(self):
+ self.rooms = []
+ for _ in range(3):
+ self.house = House.objects.create()
+ for _ in range(3):
+ self.rooms.append(Room.objects.create(house=self.house))
+
+ @override_settings(DEBUG=True)
+ def test_bug(self):
+ prefetcher = get_prefetcher(self.rooms[0], 'house')[0]
+ queryset = prefetcher.get_prefetch_queryset(list(Room.objects.all()))[0]
+ self.assertNotIn(' JOIN ', force_text(queryset.query))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment