mirror of
https://github.com/django/django.git
synced 2024-11-28 21:43:13 +01:00
Fixed #33134 -- Fixed recursion depth error when rendering Form with BoundFields.
Regression in 456466d932
.
This commit is contained in:
parent
b7fd668b37
commit
4884a87e02
@ -177,7 +177,6 @@ class BoundField:
|
||||
else:
|
||||
attrs['class'] = self.form.required_css_class
|
||||
context = {
|
||||
'form': self.form,
|
||||
'field': self,
|
||||
'label': contents,
|
||||
'attrs': attrs,
|
||||
|
@ -0,0 +1,2 @@
|
||||
{% load tags %}
|
||||
{% count_render %}
|
0
tests/forms_tests/templatetags/__init__.py
Normal file
0
tests/forms_tests/templatetags/__init__.py
Normal file
21
tests/forms_tests/templatetags/tags.py
Normal file
21
tests/forms_tests/templatetags/tags.py
Normal file
@ -0,0 +1,21 @@
|
||||
from django.template import Library, Node
|
||||
|
||||
register = Library()
|
||||
|
||||
|
||||
class CountRenderNode(Node):
|
||||
count = 0
|
||||
|
||||
def render(self, context):
|
||||
self.count += 1
|
||||
for v in context.flatten().values():
|
||||
try:
|
||||
v.render()
|
||||
except AttributeError:
|
||||
pass
|
||||
return str(self.count)
|
||||
|
||||
|
||||
@register.tag
|
||||
def count_render(parser, token):
|
||||
return CountRenderNode()
|
@ -3954,3 +3954,14 @@ class OverrideTests(SimpleTestCase):
|
||||
'<div class="error">This field is required.</div></div>'
|
||||
'<p>Comment: <input type="text" name="comment" required></p>',
|
||||
)
|
||||
|
||||
def test_cyclic_context_boundfield_render(self):
|
||||
class FirstNameForm(Form):
|
||||
first_name = CharField()
|
||||
template_name_label = 'forms_tests/cyclic_context_boundfield_render.html'
|
||||
|
||||
f = FirstNameForm()
|
||||
try:
|
||||
self.assertInHTML('<th>1</th>', f.render())
|
||||
except RecursionError:
|
||||
self.fail('Cyclic reference in BoundField.render().')
|
||||
|
Loading…
Reference in New Issue
Block a user