]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: catch any type of error if ZoneInfo creation fails
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 14 Sep 2022 11:50:05 +0000 (12:50 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 14 Sep 2022 11:50:05 +0000 (12:50 +0100)
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

psycopg/psycopg/_tz.py
psycopg_c/psycopg_c/types/datetime.pyx

index 30f846f1bef8dd409fb24d30ae6c337d02c7ca4b..58c815686d47a93182c83f89c33601eff0b1a45d 100644 (file)
@@ -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
 
index 720a852c48affd6d71eeec9cbf39245f6d6b2c7f..5d32a66d318435f21ec600ff043483988151a250 100644 (file)
@@ -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