diff --git a/django/forms/widgets.py b/django/forms/widgets.py
index 842b73e95c..d2b759c90d 100644
a
|
b
|
class SelectDateWidget(Widget):
|
1161 | 1161 | # Return pseudo-ISO dates with zeros for any unselected values, |
1162 | 1162 | # e.g. '2017-0-23'. |
1163 | 1163 | return "%s-%s-%s" % (y or 0, m or 0, d or 0) |
| 1164 | except OverflowError: |
| 1165 | return '0-0-0' |
1164 | 1166 | return date_value.strftime(input_format) |
1165 | 1167 | return data.get(name) |
1166 | 1168 | |
diff --git a/tests/forms_tests/field_tests/test_datefield.py b/tests/forms_tests/field_tests/test_datefield.py
index a9f93f40ed..587e4b0f7e 100644
a
|
b
|
|
| 1 | import sys |
1 | 2 | from datetime import date, datetime |
2 | 3 | |
3 | 4 | from django.core.exceptions import ValidationError |
… |
… |
class DateFieldTest(SimpleTestCase):
|
32 | 33 | self.assertFalse(c.is_valid()) |
33 | 34 | self.assertEqual(c.errors, {"mydate": ["Enter a valid date."]}) |
34 | 35 | |
| 36 | # Would trigger an "OverflowError: Python int too large to convert to C long". |
| 37 | c = GetDate({"mydate_month": str(sys.maxsize+1), "mydate_day": "31", "mydate_year": "2010"}) |
| 38 | self.assertFalse(c.is_valid()) |
| 39 | self.assertEqual(c.errors, {"mydate": ["Enter a valid date."]}) |
| 40 | |
35 | 41 | # label tag is correctly associated with month dropdown |
36 | 42 | d = GetDate({"mydate_month": "1", "mydate_day": "1", "mydate_year": "2010"}) |
37 | 43 | self.assertIn('<label for="id_mydate_month">', d.as_p()) |
… |
… |
class DateFieldTest(SimpleTestCase):
|
149 | 155 | f.clean("200a-10-25") |
150 | 156 | with self.assertRaisesMessage(ValidationError, "'Enter a valid date.'"): |
151 | 157 | f.clean("25/10/06") |
| 158 | with self.assertRaisesMessage(ValidationError, "'Enter a valid date.'"): |
| 159 | f.clean("0-0-0") |
152 | 160 | with self.assertRaisesMessage(ValidationError, "'This field is required.'"): |
153 | 161 | f.clean(None) |
154 | 162 | |
diff --git a/tests/forms_tests/widget_tests/test_selectdatewidget.py b/tests/forms_tests/widget_tests/test_selectdatewidget.py
index cfcd037987..ba0f981bbc 100644
a
|
b
|
|
| 1 | import sys |
1 | 2 | from datetime import date |
2 | 3 | |
3 | 4 | from django.forms import DateField, Form, SelectDateWidget |
… |
… |
class SelectDateWidgetTest(WidgetTest):
|
610 | 611 | ((None, "12", "1"), None), |
611 | 612 | (("2000", None, "1"), None), |
612 | 613 | (("2000", "12", None), None), |
| 614 | ((str(sys.maxsize+1), "12", "1"), "0-0-0"), |
613 | 615 | ] |
614 | 616 | for values, expected in tests: |
615 | 617 | with self.subTest(values=values): |