From db987250c8cb8049fd5e4c55f23c1c1b9b0fdc44 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sat, 14 Jan 2012 18:01:15 +0000 Subject: [PATCH] Avoid installing Error.__reduce_ex__ on Python 2.4 It is not used by the pickle protocol, and if called manually fails in an unsettling way, probably because the exceptions were old-style classes. --- psycopg/psycopgmodule.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/psycopg/psycopgmodule.c b/psycopg/psycopgmodule.c index ea04e658..438b018e 100644 --- a/psycopg/psycopgmodule.c +++ b/psycopg/psycopgmodule.c @@ -478,7 +478,12 @@ psyco_errors_init(void) PyObject_SetAttrString(Error, "pgcode", Py_None); PyObject_SetAttrString(Error, "cursor", Py_None); - /* install __reduce_ex__ on Error to make all the subclasses picklable */ + /* install __reduce_ex__ on Error to make all the subclasses picklable. + * + * Don't install it on Py 2.4: it is not used by the pickle + * protocol, and if called manually fails in an unsettling way, + * probably because the exceptions were old-style classes. */ +#if PY_VERSION_HEX >= 0x02050000 if (!(descr = PyDescr_NewMethod((PyTypeObject *)Error, &psyco_error_reduce_ex_def))) { goto exit; @@ -488,6 +493,7 @@ psyco_errors_init(void) goto exit; } Py_DECREF(descr); +#endif rv = 0;