From 51027dbd5f30c855d77a44841cf6afaa07af7857 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 20 May 2018 13:22:38 +0100 Subject: [PATCH] Raise NotSupportedError fetching iso_8601 intervals Previously it would have failed parsing and resulted in ValueError Close #707 --- psycopg/typecast_datetime.c | 5 +++++ tests/test_dates.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/psycopg/typecast_datetime.c b/psycopg/typecast_datetime.c index f24223cb..e34117dd 100644 --- a/psycopg/typecast_datetime.c +++ b/psycopg/typecast_datetime.c @@ -406,6 +406,11 @@ typecast_PYINTERVAL_cast(const char *str, Py_ssize_t len, PyObject *curs) } break; + case 'P': + PyErr_SetString(NotSupportedError, + "iso_8601 intervalstyle currently not supported"); + return NULL; + default: break; } diff --git a/tests/test_dates.py b/tests/test_dates.py index df088eed..b693fcde 100755 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -437,6 +437,13 @@ class DatetimeTests(ConnectingTestCase, CommonDatetimeTestsMixin): r = cur.fetchone()[0] self.assertEqual(r, v, "%s -> %s != %s" % (s, r, v)) + def test_interval_iso_8601_not_supported(self): + # We may end up supporting, but no pressure for it + cur = self.conn.cursor() + cur.execute("set local intervalstyle to iso_8601") + cur.execute("select '1 day 2 hours'::interval") + self.assertRaises(psycopg2.NotSupportedError, cur.fetchone) + # Only run the datetime tests if psycopg was compiled with support. if not hasattr(psycopg2.extensions, 'PYDATETIME'):