Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: django/django
...
head fork: akaariai/django
compare: only_load_bug
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 01, 2013
@akaariai akaariai Test for only_load failure a7a7f3b
Showing with 34 additions and 0 deletions.
  1. +34 −0 tests/queries/tests.py
View
34 tests/queries/tests.py
@@ -3071,3 +3071,37 @@ def test_ticket_20955(self):
task_get.creator.staffuser.staff)
self.assertEqual(task_select_related.owner.staffuser.staff,
task_get.owner.staffuser.staff)
+
+class OnlyLoadBugTests(TestCase):
+ def test_only_load_bug(self):
+ category1 = NamedCategory.objects.create(name='category1')
+ category2 = NamedCategory.objects.create(name='category2')
+ category3 = NamedCategory.objects.create(name='category3')
+ t1 = Tag.objects.create(name='t1', category=category1)
+ t2 = Tag.objects.create(name='t2', category=category2, parent=t1)
+ t3 = Tag.objects.create(name='t3', category=category3, parent=t2)
+ qs = Tag.objects.select_related(
+ 'parent', 'parent__parent'
+ ).defer(
+ 'parent__name', 'parent__parent__category'
+ ).filter(pk=t3.pk)
+ self.assertQuerysetEqual(qs, [t3], lambda x: x)
+ # Force re-evaluation for assertNumQueries
+ qs = qs.all()
+ with self.assertNumQueries(1):
+ qs_t3 = qs[0]
+ self.assertEqual(qs_t3, t3)
+ qs_t2 = qs_t3.parent
+ self.assertEqual(qs_t2, t2)
+ qs_t1 = qs_t2.parent
+ self.assertEqual(qs_t1, t1)
+ with self.assertNumQueries(0):
+ self.assertEqual(qs_t1.name, 't1')
+ self.assertEqual(qs_t3.name, 't3')
+ self.assertEqual(qs_t1.category_id, category1.pk)
+ self.assertEqual(qs_t2.category_id, category2.pk)
+ # parent__name and parent__parent__category were deferred
+ with self.assertNumQueries(1):
+ self.assertEqual(qs_t2.name, 't2')
+ with self.assertNumQueries(1):
+ self.assertEqual(qs_t3.category, category3)

No commit comments for this range

Something went wrong with that request. Please try again.