From 22575528bedcdbf3d9daede6d2808f16684dbc99 Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Mon, 3 May 2021 15:14:07 +0200 Subject: [PATCH 1/3] Don't abort if sqlstate_errors already initialized --- psycopg/psycopgmodule.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index 36fd1f9c..2a4c9e6a 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -770,9 +770,8 @@ sqlstate_errors_init(PyObject *module) Dprintf("psycopgmodule: initializing sqlstate exceptions"); if (sqlstate_errors) { - PyErr_SetString(PyExc_SystemError, - "sqlstate_errors_init(): already called"); - goto exit; + Dprintf("sqlstate_errors_init(): already called"); + return 0; } if (!(errmodule = PyImport_ImportModule("psycopg2.errors"))) { /* don't inject the exceptions into the errors module */ From f59d626fe337260321c6bce60ce2da4b8577d4c9 Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Mon, 3 May 2021 23:30:13 +0200 Subject: [PATCH 2/3] Don't re-initialize psycoEncodings if already initialized --- psycopg/psycopgmodule.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index 2a4c9e6a..d448d010 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -608,6 +608,10 @@ encodings_init(PyObject *module) int rv = -1; Dprintf("psycopgmodule: initializing encodings table"); + if (psycoEncodings) { + Dprintf("encodings_init(): already called"); + return 0; + } if (!(psycoEncodings = PyDict_New())) { goto exit; } Py_INCREF(psycoEncodings); From 3487f627e2b8afb2e1dcd8abfc1b6ce94380b1bb Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 20 May 2021 16:16:51 +0200 Subject: [PATCH 3/3] Mention sqlstate reinit in NEWS file --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 35044bcd..bdd30df8 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ What's new in psycopg 2.8.7 - Accept empty params as `~psycopg2.connect()` (:ticket:`#1250`). - Fix attributes refcount in `Column` initialisation (:ticket:`#1252`). +- Allow re-initialisation of static variables in the C module (:ticket:`#1267`). What's new in psycopg 2.8.6