diff --git a/NEWS b/NEWS index c6f9ab1e..3f1b7bae 100644 --- a/NEWS +++ b/NEWS @@ -1,10 +1,16 @@ Current release --------------- +What's new in psycopg 2.9.2 +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Raise `ValueError` for dates >= Y10k (:ticket:`#1307`) + + What's new in psycopg 2.9.1 ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Fix regression with named `sql.Placeholder` (:ticket:`1291`). +Fix regression with named `sql.Placeholder` (:ticket:`#1291`). What's new in psycopg 2.9 diff --git a/psycopg/typecast_datetime.c b/psycopg/typecast_datetime.c index e5e5110d..44e1d315 100644 --- a/psycopg/typecast_datetime.c +++ b/psycopg/typecast_datetime.c @@ -71,7 +71,6 @@ typecast_PYDATE_cast(const char *str, Py_ssize_t len, PyObject *curs) return NULL; } else { - if (y > 9999) y = 9999; obj = PyObject_CallFunction( (PyObject*)PyDateTimeAPI->DateType, "iii", y, m, d); } @@ -172,8 +171,6 @@ _parse_noninftz(const char *str, Py_ssize_t len, PyObject *curs) mm += 1; ss -= 60; } - if (y > 9999) - y = 9999; tzinfo_factory = ((cursorObject *)curs)->tzinfo_factory; if (n >= 5 && tzinfo_factory != Py_None) { diff --git a/tests/test_dates.py b/tests/test_dates.py index 7f52a916..333dbedd 100755 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -115,12 +115,26 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin): self.DATETIME = psycopg2.extensions.PYDATETIME self.INTERVAL = psycopg2.extensions.PYINTERVAL + def test_parse_10k_date(self): + # datetime does not support dates larger than date.max + self.assertEqual(self.DATE('9999-12-31', self.curs), date(9999, 12, 31)) + self.assertRaises(ValueError, self.DATE, '10000-01-01', self.curs) + def test_parse_bc_date(self): # datetime does not support BC dates + self.assertEqual(self.DATE('0001-01-01', self.curs), date(1, 1, 1)) self.assertRaises(ValueError, self.DATE, '00042-01-01 BC', self.curs) + def test_parse_10k_datetime(self): + # datetime does not support dates larger than date.max + self.assertEqual(self.DATETIME('9999-12-31 23:59:59', self.curs), + datetime(9999, 12, 31, 23, 59, 59)) + self.assertRaises(ValueError, self.DATE, '10000-01-01', self.curs) + def test_parse_bc_datetime(self): # datetime does not support BC dates + self.assertEqual(self.DATETIME('0001-01-01 13:30:29', self.curs), + datetime(1, 1, 1, 13, 30, 29)) self.assertRaises(ValueError, self.DATETIME, '00042-01-01 13:30:29 BC', self.curs)