Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #11183 - BaseForm init leaves pointers pointing back to…

… base_fields

  
Thanks to margieroginski for the report

Backport of [12733] from trunk


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12736 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 89c263932378fa4b370ab28ef7658472f31643e0 1 parent f13b17a
Luke Plant authored March 09, 2010
6  django/forms/models.py
@@ -952,6 +952,12 @@ def __init__(self, queryset, empty_label=u"---------", cache_choices=False,
952 952
         self.choice_cache = None
953 953
         self.to_field_name = to_field_name
954 954
 
  955
+    def __deepcopy__(self, memo):
  956
+        result = super(ChoiceField, self).__deepcopy__(memo)
  957
+        # Need to force a new ModelChoiceIterator to be created, bug #11183
  958
+        result.queryset = result.queryset
  959
+        return result
  960
+
955 961
     def _get_queryset(self):
956 962
         return self._queryset
957 963
 
16  tests/regressiontests/model_forms_regress/tests.py
@@ -2,7 +2,7 @@
2 2
 
3 3
 from django import db
4 4
 from django import forms
5  
-from django.forms.models import modelform_factory
  5
+from django.forms.models import modelform_factory, ModelChoiceField
6 6
 from django.conf import settings
7 7
 from django.test import TestCase
8 8
 
@@ -107,3 +107,17 @@ def test_no_model_class(self):
107 107
         class NoModelModelForm(forms.ModelForm):
108 108
             pass
109 109
         self.assertRaises(ValueError, NoModelModelForm)
  110
+
  111
+
  112
+class ModelChoiceForm(forms.Form):
  113
+    person = ModelChoiceField(Person.objects.all())
  114
+
  115
+
  116
+class TestTicket11183(TestCase):
  117
+    def test_11183(self):
  118
+        form1 = ModelChoiceForm()
  119
+        field1 = form1.fields['person']
  120
+        # To allow the widget to change the queryset of field1.widget.choices correctly, 
  121
+        # without affecting other forms, the following must hold:
  122
+        self.assert_(field1 is not ModelChoiceForm.base_fields['person'])
  123
+        self.assert_(field1.widget.choices.field is field1)

0 notes on commit 89c2639

Please sign in to comment.
Something went wrong with that request. Please try again.