From 901b3228191264cca4f272172dd0c094cf45ebaa Mon Sep 17 00:00:00 2001 From: vimiix Date: Mon, 19 Aug 2024 17:53:56 +0800 Subject: [PATCH] feat: illegal datetime values are returned as str(#I90GIP) --- psycopg/typecast_datetime.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/psycopg/typecast_datetime.c b/psycopg/typecast_datetime.c index e5e5110..93210c8 100644 --- a/psycopg/typecast_datetime.c +++ b/psycopg/typecast_datetime.c @@ -203,6 +203,11 @@ _parse_noninftz(const char *str, Py_ssize_t len, PyObject *curs) rv = PyObject_CallFunction( (PyObject*)PyDateTimeAPI->DateTimeType, "iiiiiiiO", y, m, d, hh, mm, ss, us, tzinfo); + if (rv == NULL) { + /* illegal values are returned as str */ + PyErr_Clear(); + rv = PyUnicode_FromString(str); + } exit: Py_XDECREF(tzoff);