diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 842b73e95c..3d6091c250 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -1161,6 +1161,8 @@ class SelectDateWidget(Widget): # Return pseudo-ISO dates with zeros for any unselected values, # e.g. '2017-0-23'. return "%s-%s-%s" % (y or 0, m or 0, d or 0) + except OverflowError: + return "0-0-0" return date_value.strftime(input_format) return data.get(name) diff --git a/tests/forms_tests/field_tests/test_datefield.py b/tests/forms_tests/field_tests/test_datefield.py index 60c8043be3..65ac76319d 100644 --- a/tests/forms_tests/field_tests/test_datefield.py +++ b/tests/forms_tests/field_tests/test_datefield.py @@ -1,3 +1,4 @@ +import sys from datetime import date, datetime from django.core.exceptions import ValidationError @@ -36,6 +37,17 @@ class DateFieldTest(SimpleTestCase): d = GetDate({"mydate_month": "1", "mydate_day": "1", "mydate_year": "2010"}) self.assertIn('