summaryrefslogtreecommitdiff
path: root/tests/defer
diff options
context:
space:
mode:
authorAnssi Kääriäinen <anssi.kaariainen@thl.fi>2016-02-02 11:33:09 +0200
committerTim Graham <timograham@gmail.com>2016-04-29 13:06:32 -0400
commit7f51876f99851fdc3fef63aecdfbcffa199c26b9 (patch)
tree9b2fc6cda60771d699c85a5259ba80b120417fcd /tests/defer
parentdac075e9103ba961af4f70b4011616daa72985d4 (diff)
downloaddjango-7f51876f99851fdc3fef63aecdfbcffa199c26b9.tar.gz
Fixed #26207 -- Replaced dynamic classes with non-data descriptors for deferred instance loading.
Diffstat (limited to 'tests/defer')
-rw-r--r--tests/defer/tests.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/tests/defer/tests.py b/tests/defer/tests.py
index b148c31906..8303ab5068 100644
--- a/tests/defer/tests.py
+++ b/tests/defer/tests.py
@@ -1,6 +1,6 @@
from __future__ import unicode_literals
-from django.db.models.query_utils import DeferredAttribute, InvalidQuery
+from django.db.models.query_utils import InvalidQuery
from django.test import TestCase
from .models import (
@@ -15,10 +15,7 @@ class AssertionMixin(object):
we examine attribute values. Therefore, this method returns the number
of deferred fields on returned instances.
"""
- count = 0
- for field in obj._meta.fields:
- if isinstance(obj.__class__.__dict__.get(field.attname), DeferredAttribute):
- count += 1
+ count = len(obj.get_deferred_fields())
self.assertEqual(count, num)
@@ -45,7 +42,9 @@ class DeferTests(AssertionMixin, TestCase):
# of them except the model's primary key see #15494
self.assert_delayed(qs.only("pk")[0], 3)
# You can use 'pk' with reverse foreign key lookups.
- self.assert_delayed(self.s1.primary_set.all().only('pk')[0], 3)
+ # The related_id is alawys set even if it's not fetched from the DB,
+ # so pk and related_id are not deferred.
+ self.assert_delayed(self.s1.primary_set.all().only('pk')[0], 2)
def test_defer_only_chaining(self):
qs = Primary.objects.all()