Ticket #34424: diff.patch

File diff.patch, 2.7 KB (added by Jure Slak, 20 months ago)

patch

  • django/forms/widgets.py

    diff --git a/django/forms/widgets.py b/django/forms/widgets.py
    index 842b73e95c..d2b759c90d 100644
    a b class SelectDateWidget(Widget):  
    11611161                # Return pseudo-ISO dates with zeros for any unselected values,
    11621162                # e.g. '2017-0-23'.
    11631163                return "%s-%s-%s" % (y or 0, m or 0, d or 0)
     1164            except OverflowError:
     1165                return '0-0-0'
    11641166            return date_value.strftime(input_format)
    11651167        return data.get(name)
    11661168
  • tests/forms_tests/field_tests/test_datefield.py

    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  
     1import sys
    12from datetime import date, datetime
    23
    34from django.core.exceptions import ValidationError
    class DateFieldTest(SimpleTestCase):  
    3233        self.assertFalse(c.is_valid())
    3334        self.assertEqual(c.errors, {"mydate": ["Enter a valid date."]})
    3435
     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
    3541        # label tag is correctly associated with month dropdown
    3642        d = GetDate({"mydate_month": "1", "mydate_day": "1", "mydate_year": "2010"})
    3743        self.assertIn('<label for="id_mydate_month">', d.as_p())
    class DateFieldTest(SimpleTestCase):  
    149155            f.clean("200a-10-25")
    150156        with self.assertRaisesMessage(ValidationError, "'Enter a valid date.'"):
    151157            f.clean("25/10/06")
     158        with self.assertRaisesMessage(ValidationError, "'Enter a valid date.'"):
     159            f.clean("0-0-0")
    152160        with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
    153161            f.clean(None)
    154162
  • tests/forms_tests/widget_tests/test_selectdatewidget.py

    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  
     1import sys
    12from datetime import date
    23
    34from django.forms import DateField, Form, SelectDateWidget
    class SelectDateWidgetTest(WidgetTest):  
    610611            ((None, "12", "1"), None),
    611612            (("2000", None, "1"), None),
    612613            (("2000", "12", None), None),
     614            ((str(sys.maxsize+1), "12", "1"), "0-0-0"),
    613615        ]
    614616        for values, expected in tests:
    615617            with self.subTest(values=values):
Back to Top