Loading django/forms/widgets.py +2 −2 Original line number Diff line number Diff line Loading @@ -977,10 +977,10 @@ class SelectDateWidget(Widget): year_val, month_val, day_val = v.year, v.month, v.day except ValueError: pass else: if year_val is None: match = self.date_re.match(value) if match: year_val, month_val, day_val = [int(v) for v in match.groups()] year_val, month_val, day_val = [int(val) for val in match.groups()] html = {} choices = [(i, i) for i in self.years] html['year'] = self.create_select(name, self.year_field, value, year_val, choices, self.year_none_value) Loading tests/forms_tests/tests/test_widgets.py +3 −0 Original line number Diff line number Diff line Loading @@ -1875,6 +1875,9 @@ class SelectDateWidgetTests(TestCase): """, ) # Even with an invalid date, the widget should reflect the entered value (#17401). self.assertEqual(w.render('mydate', '2010-02-30').count('selected="selected"'), 3) # Years before 1900 work w = SelectDateWidget(years=('1899',)) self.assertEqual( Loading Loading
django/forms/widgets.py +2 −2 Original line number Diff line number Diff line Loading @@ -977,10 +977,10 @@ class SelectDateWidget(Widget): year_val, month_val, day_val = v.year, v.month, v.day except ValueError: pass else: if year_val is None: match = self.date_re.match(value) if match: year_val, month_val, day_val = [int(v) for v in match.groups()] year_val, month_val, day_val = [int(val) for val in match.groups()] html = {} choices = [(i, i) for i in self.years] html['year'] = self.create_select(name, self.year_field, value, year_val, choices, self.year_none_value) Loading
tests/forms_tests/tests/test_widgets.py +3 −0 Original line number Diff line number Diff line Loading @@ -1875,6 +1875,9 @@ class SelectDateWidgetTests(TestCase): """, ) # Even with an invalid date, the widget should reflect the entered value (#17401). self.assertEqual(w.render('mydate', '2010-02-30').count('selected="selected"'), 3) # Years before 1900 work w = SelectDateWidget(years=('1899',)) self.assertEqual( Loading