From: Daniele Varrazzo Date: Sun, 14 Nov 2021 18:30:18 +0000 (+0100) Subject: Initialize UTC in the timezones cache X-Git-Tag: 3.0.4~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c3942849f9243b276e27e3bdc0c3ca0e1bbb99b;p=thirdparty%2Fpsycopg.git Initialize UTC in the timezones cache Not having it might cause spurious errors in particular cases, we see it failing sometimes in the CI on Windows (which lacks the timezone database) on Python 3.6 with a ridiculous: unknown PostgreSQL timezone: 'UTC'; will use UTC The similar cache on the Python side is primed the same way. --- diff --git a/psycopg_c/psycopg_c/types/datetime.pyx b/psycopg_c/psycopg_c/types/datetime.pyx index 4f7d22576..448ddd173 100644 --- a/psycopg_c/psycopg_c/types/datetime.pyx +++ b/psycopg_c/psycopg_c/types/datetime.pyx @@ -1105,13 +1105,17 @@ cdef object _timezone_from_seconds(int sec, __cache={}): return tz -cdef object _timezone_from_connection(pq.PGconn pgconn, __cache={}): +cdef _timezones = {} +_timezones[None] = timezone_utc +_timezones[b"UTC"] = timezone_utc + +cdef object _timezone_from_connection(pq.PGconn pgconn): """Return the Python timezone info of the connection's timezone.""" if pgconn is None: return timezone_utc - tzname = libpq.PQparameterStatus(pgconn._pgconn_ptr, b"TimeZone") - cdef PyObject *ptr = PyDict_GetItem(__cache, tzname) + cdef bytes tzname = libpq.PQparameterStatus(pgconn._pgconn_ptr, b"TimeZone") + cdef PyObject *ptr = PyDict_GetItem(_timezones, tzname) if ptr != NULL: return ptr @@ -1130,7 +1134,7 @@ cdef object _timezone_from_connection(pq.PGconn pgconn, __cache={}): ) zi = timezone_utc - __cache[tzname] = zi + _timezones[tzname] = zi return zi