mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #17439 -- Prevented spurious queries for missing objects after prefetch_related has run.
That affects nullable foreign key, nullable one-to-one, and reverse one-to-one relations. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17899 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -68,6 +68,14 @@ class PrefetchRelatedTests(TestCase):
|
||||
|
||||
self.assertQuerysetEqual(self.book2.authors.all(), [u"<Author: Charlotte>"])
|
||||
|
||||
def test_onetoone_reverse_no_match(self):
|
||||
# Regression for #17439
|
||||
with self.assertNumQueries(2):
|
||||
book = Book.objects.prefetch_related('bookwithyear').all()[0]
|
||||
with self.assertNumQueries(0):
|
||||
with self.assertRaises(BookWithYear.DoesNotExist):
|
||||
book.bookwithyear
|
||||
|
||||
def test_survives_clone(self):
|
||||
with self.assertNumQueries(2):
|
||||
lists = [list(b.first_time_authors.all())
|
||||
|
||||
Reference in New Issue
Block a user