mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-25 18:33:44 +03:00
Fixed pickling of exceptions with no pgerror/pgcode set
Fixes ticket #170.
This commit is contained in:
parent
81e8b869d0
commit
345077d5f7
7
NEWS
7
NEWS
|
@ -1,6 +1,13 @@
|
||||||
Current release
|
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
|
What's new in psycopg 2.5.1
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
|
|
@ -163,8 +163,16 @@ psyco_error_reduce(errorObject *self)
|
||||||
if (2 != PyTuple_GET_SIZE(tuple)) { goto exit; }
|
if (2 != PyTuple_GET_SIZE(tuple)) { goto exit; }
|
||||||
|
|
||||||
if (!(dict = PyDict_New())) { goto error; }
|
if (!(dict = PyDict_New())) { goto error; }
|
||||||
if (0 != PyDict_SetItemString(dict, "pgerror", self->pgerror)) { goto error; }
|
if (self->pgerror) {
|
||||||
if (0 != PyDict_SetItemString(dict, "pgcode", self->pgcode)) { goto error; }
|
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;
|
PyObject *newtuple;
|
||||||
|
|
|
@ -279,6 +279,21 @@ class ExceptionsTestCase(ConnectingTestCase):
|
||||||
self.assertEqual(e.pgcode, e1.pgcode)
|
self.assertEqual(e.pgcode, e1.pgcode)
|
||||||
self.assert_(e1.cursor is None)
|
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():
|
def test_suite():
|
||||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user