diff --git a/django/forms/boundfield.py b/django/forms/boundfield.py index a8e81afe9b..c2c598ca6b 100644 --- a/django/forms/boundfield.py +++ b/django/forms/boundfield.py @@ -10,7 +10,7 @@ from django.utils.deprecation import RemovedInDjango21Warning from django.utils.encoding import force_text, python_2_unicode_compatible from django.utils.functional import cached_property from django.utils.html import conditional_escape, format_html, html_safe -from django.utils.inspect import func_supports_parameter +from django.utils.inspect import func_accepts_kwargs, func_supports_parameter from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ @@ -112,7 +112,7 @@ class BoundField(object): name = self.html_initial_name kwargs = {} - if func_supports_parameter(widget.render, 'renderer'): + if func_supports_parameter(widget.render, 'renderer') or func_accepts_kwargs(widget.render): kwargs['renderer'] = self.form.renderer else: warnings.warn( diff --git a/docs/releases/1.11.3.txt b/docs/releases/1.11.3.txt index 7eacbd8a36..15200fafd5 100644 --- a/docs/releases/1.11.3.txt +++ b/docs/releases/1.11.3.txt @@ -9,4 +9,6 @@ Django 1.11.3 fixes several bugs in 1.11.2. Bugfixes ======== -* ... +* Removed an incorrect deprecation warning about a missing ``renderer`` + argument if a ``Widget.render()`` method accepts ``**kwargs`` + (:ticket:`28265`). diff --git a/tests/forms_tests/widget_tests/test_render_deprecation.py b/tests/forms_tests/widget_tests/test_render_deprecation.py new file mode 100644 index 0000000000..fc979957fb --- /dev/null +++ b/tests/forms_tests/widget_tests/test_render_deprecation.py @@ -0,0 +1,30 @@ +from django import forms +from django.test import SimpleTestCase +from django.utils.deprecation import RemovedInDjango21Warning + + +class RenderDeprecationTests(SimpleTestCase): + def test_custom_widget_renderer_warning(self): + class CustomWidget1(forms.TextInput): + def render(self, name, value, attrs=None, renderer=None): + return super(CustomWidget1, self).render(name, value, attrs, renderer) + + class CustomWidget2(forms.TextInput): + def render(self, *args, **kwargs): + return super(CustomWidget2, self).render(*args, **kwargs) + + class CustomWidget3(forms.TextInput): + def render(self, name, value, attrs=None): + return super(CustomWidget3, self).render(name, value, attrs) + + class MyForm(forms.Form): + foo = forms.CharField(widget=CustomWidget1) + bar = forms.CharField(widget=CustomWidget2) + baz = forms.CharField(widget=CustomWidget3) + + form = MyForm() + str(form['foo']) # No warning. + str(form['bar']) # No warning. + msg = "Add the `renderer` argument to the render() method of