Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed pickling of exceptions with no pgerror/pgcode set

Fixes ticket #170.
  • Loading branch information...
commit 0e08fbb20b9f5bf004d8ab7c150711aac486f396 1 parent 96248d0
@dvarrazzo authored
Showing with 32 additions and 2 deletions.
  1. +7 −0 NEWS
  2. +10 −2 psycopg/error_type.c
  3. +15 −0 tests/test_module.py
View
7 NEWS
@@ -1,6 +1,13 @@
Current release
---------------
+What's new in psycopg 2.5.2
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Fixed segfault pickling the exception raised on connection error
+ (:ticket:`#170`).
+
+
What's new in psycopg 2.5.1
^^^^^^^^^^^^^^^^^^^^^^^^^^^
View
12 psycopg/error_type.c
@@ -163,8 +163,16 @@ psyco_error_reduce(errorObject *self)
if (2 != PyTuple_GET_SIZE(tuple)) { goto exit; }
if (!(dict = PyDict_New())) { goto error; }
- if (0 != PyDict_SetItemString(dict, "pgerror", self->pgerror)) { goto error; }
- if (0 != PyDict_SetItemString(dict, "pgcode", self->pgcode)) { goto error; }
+ if (self->pgerror) {
+ if (0 != PyDict_SetItemString(dict, "pgerror", self->pgerror)) {
+ goto error;
+ }
+ }
+ if (self->pgcode) {
+ if (0 != PyDict_SetItemString(dict, "pgcode", self->pgcode)) {
+ goto error;
+ }
+ }
{
PyObject *newtuple;
View
15 tests/test_module.py
@@ -279,6 +279,21 @@ def test_pickle(self):
self.assertEqual(e.pgcode, e1.pgcode)
self.assert_(e1.cursor is None)
+ @skip_before_python(2, 5)
+ def test_pickle_connection_error(self):
+ # segfaults on psycopg 2.5.1 - see ticket #170
+ import pickle
+ try:
+ psycopg2.connect('dbname=nosuchdatabasemate')
+ except psycopg2.Error, exc:
+ e = exc
+
+ e1 = pickle.loads(pickle.dumps(e))
+
+ self.assertEqual(e.pgerror, e1.pgerror)
+ self.assertEqual(e.pgcode, e1.pgcode)
+ self.assert_(e1.cursor is None)
+
def test_suite():
return unittest.TestLoader().loadTestsFromName(__name__)
Please sign in to comment.
Something went wrong with that request. Please try again.