From a1b1df2d887f527f710d970654dea96321060325 Mon Sep 17 00:00:00 2001
From: Luke Benstead <kazade@gmail.com>
Date: Tue, 14 Mar 2017 13:12:16 +0000
Subject: [PATCH] Demonstrate that .queryset._result_cache persists across form
 instantiations

---
 tests/model_forms/tests.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index b92ba1f..47236a6 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -2815,6 +2815,7 @@ class LimitChoicesToTests(TestCase):
     """
     Tests the functionality of ``limit_choices_to``.
     """
+
     @classmethod
     def setUpTestData(cls):
         cls.threepwood = Character.objects.create(
@@ -2831,6 +2832,9 @@ class LimitChoicesToTests(TestCase):
         A ForeignKey can use limit_choices_to as a callable (#2554).
         """
         stumpjokeform = StumpJokeForm()
+
+        # Check that the result_cache is empty for new forms
+        self.assertFalse(stumpjokeform.fields['most_recently_fooled'].queryset._result_cache)
         self.assertSequenceEqual(stumpjokeform.fields['most_recently_fooled'].queryset, [self.threepwood])
 
     def test_limit_choices_to_callable_for_m2m_rel(self):
@@ -2838,6 +2842,9 @@ class LimitChoicesToTests(TestCase):
         A ManyToManyField can use limit_choices_to as a callable (#2554).
         """
         stumpjokeform = StumpJokeForm()
+
+        # Check that the result_cache is empty for new forms
+        self.assertFalse(stumpjokeform.fields['most_recently_fooled'].queryset._result_cache)
         self.assertSequenceEqual(stumpjokeform.fields['most_recently_fooled'].queryset, [self.threepwood])
 
     def test_custom_field_with_queryset_but_no_limit_choices_to(self):
-- 
2.9.3

