From: Daniele Varrazzo Date: Wed, 14 Sep 2022 11:50:05 +0000 (+0100) Subject: fix: catch any type of error if ZoneInfo creation fails X-Git-Tag: 3.1.2~9^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e20f1c3c91eebcf8495bdd63ac543b9cbfc6b772;p=thirdparty%2Fpsycopg.git fix: catch any type of error if ZoneInfo creation fails OSError would be enough to solve the problem reported in #371. However, in case of error, Windows C implementation segfaults. I would prefer to not chase this error just because of weirdness in the tzdata external library, so let's cast a wider net. Fix #371 --- diff --git a/psycopg/psycopg/_tz.py b/psycopg/psycopg/_tz.py index 30f846f1b..58c815686 100644 --- a/psycopg/psycopg/_tz.py +++ b/psycopg/psycopg/_tz.py @@ -28,7 +28,7 @@ def get_tzinfo(pgconn: Optional[PGconn]) -> tzinfo: sname = tzname.decode() if tzname else "UTC" try: zi: tzinfo = ZoneInfo(sname) - except KeyError: + except (KeyError, OSError): logger.warning("unknown PostgreSQL timezone: %r; will use UTC", sname) zi = timezone.utc diff --git a/psycopg_c/psycopg_c/types/datetime.pyx b/psycopg_c/psycopg_c/types/datetime.pyx index 720a852c4..5d32a66d3 100644 --- a/psycopg_c/psycopg_c/types/datetime.pyx +++ b/psycopg_c/psycopg_c/types/datetime.pyx @@ -1104,7 +1104,7 @@ cdef object _timezone_from_connection(pq.PGconn pgconn): sname = tzname.decode() if tzname else "UTC" try: zi = ZoneInfo(sname) - except KeyError: + except (KeyError, OSError): logger = logging.getLogger("psycopg") logger.warning( "unknown PostgreSQL timezone: %r; will use UTC", sname