#8436 closed (invalid)
Silent crash in forms rendering
| Reported by: | stilldodge | Owned by: | nobody |
|---|---|---|---|
| Component: | Forms | Version: | dev |
| Severity: | Keywords: | errors, Form | |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Given form as follows, as_table crashes
I expect this has to do with collisions to properties of Form and variations of problems will probably happen with (errors, changed_data, media)
class TestForm(forms.ModelForm): errors = forms.CharField(widget=forms.HiddenInput) class Meta: model = MyModel
Stack trace
c:\django\django\forms\forms.py in as_table(self)
175 def as_table(self):
176 "Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
--> 177 return self._html_output(u'<tr><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', u'<tr><td colsp
"2">%s</td></tr>', '</td></tr>', u'<br />%s', False)
178
179 def as_ul(self):
c:\django\django\forms\forms.py in _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row)
131 def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row):
132 "Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()."
--> 133 top_errors = self.non_field_errors() # Errors that should be displayed above all fields.
134 output, hidden_fields = [], []
135 for name, field in self.fields.items():
c:\django\django\forms\forms.py in non_field_errors(self)
191 are none.
192 """
--> 193 return self.errors.get(NON_FIELD_ERRORS, self.error_class())
194
195 def full_clean(self):
AttributeError: 'CharField' object has no attribute 'get'
Change History (6)
comment:1 by , 17 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 17 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
I strongly suspect this was fixed in [8618].
comment:3 by , 17 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
With latest 8880 svn this still happens, this is based on current ModelForm docs for overriding fields
class TestModel(models.Model):
errors = models.CharField(max_length=100)
tm = TestModel()
class TestForm(forms.ModelForm):
errors=forms.CharField(widget=forms.HiddenInput)
class Meta:
model = TestModel
tf=TestForm(tm)
tf.as_table()
In [9]: tf.as_table()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
C:\dev\scms\<ipython console> in <module>()
c:\django\django\forms\forms.py in as_table(self)
181 def as_table(self):
182 "Returns this form rendered as HTML <tr>s -- excluding the <table></table>."
--> 183 return self._html_output(u'<tr><th>%(label)s</th><td>%(errors)s%(field)s%(help_text)s</td></tr>', u'<tr><td colspan=
"2">%s</td></tr>', '</td></tr>', u'<br />%s', False)
184
185 def as_ul(self):
c:\django\django\forms\forms.py in _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row)
137 def _html_output(self, normal_row, error_row, row_ender, help_text_html, errors_on_separate_row):
138 "Helper function for outputting HTML. Used by as_table(), as_ul(), as_p()."
--> 139 top_errors = self.non_field_errors() # Errors that should be displayed above all fields.
140 output, hidden_fields = [], []
141 for name, field in self.fields.items():
c:\django\django\forms\forms.py in non_field_errors(self)
197 are none.
198 """
--> 199 return self.errors.get(NON_FIELD_ERRORS, self.error_class())
200
201 def full_clean(self):
c:\django\django\forms\forms.py in _get_errors(self)
109 "Returns an ErrorDict for the data provided for the form"
110 if self._errors is None:
--> 111 self.full_clean()
112 return self._errors
113 errors = property(_get_errors)
c:\django\django\forms\forms.py in full_clean(self)
216 # Each widget type knows how to retrieve its own data, because some
217 # widgets split data over several HTML fields.
--> 218 value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
219 try:
220 if isinstance(field, FileField):
c:\django\django\forms\widgets.py in value_from_datadict(self, data, files, name)
168 of this widget. Returns None if it's not provided.
169 """
--> 170 return data.get(name, None)
171
172 def _has_changed(self, initial, data):
AttributeError: 'TestModel' object has no attribute 'get'
In [10]:
comment:4 by , 17 years ago
| milestone: | → 1.0 |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
I can confirm that this is still an open bug (after changeset r8877)
comment:5 by , 17 years ago
| Resolution: | → invalid |
|---|---|
| Status: | reopened → closed |
This is just an error. If you're trying to create a form using an instance, you have to call
TestForm(instance=tm)
That's documented here, so at least the current documentation is correct.
Fixed description formatting.