diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 4f028d34ad..801067ee38 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -268,6 +268,7 @@ class Input(Widget): def __init__(self, attrs=None): if attrs is not None: + attrs = attrs.copy() self.input_type = attrs.pop('type', self.input_type) super(Input, self).__init__(attrs) diff --git a/tests/forms_tests/widget_tests/test_input.py b/tests/forms_tests/widget_tests/test_input.py new file mode 100644 index 0000000000..e773d94d8a --- /dev/null +++ b/tests/forms_tests/widget_tests/test_input.py @@ -0,0 +1,15 @@ +from django.forms.widgets import Input + +from .base import WidgetTest + + +class InputTests(WidgetTest): + + def test_attrs_with_type(self): + attrs = {'type': 'date'} + widget = Input(attrs) + self.check_html(widget, 'name', 'value', '') + # reuse the same attrs for another widget + self.check_html(Input(attrs), 'name', 'value', '') + attrs['type'] = 'number' # shouldn't change the widget type + self.check_html(widget, 'name', 'value', '')