A prepared connection can't be canceled.

This commit is contained in:
Daniele Varrazzo 2010-11-28 12:15:26 +00:00
parent 4dbd4344a3
commit 0c7b0a943b
3 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,8 @@
* Cancel patch from Jan integrated. * Cancel patch from Jan integrated.
* psycopg/connection_type.c: can't cancel a prepared connection
2010-11-22 Daniele Varrazzo <daniele.varrazzo@gmail.com> 2010-11-22 Daniele Varrazzo <daniele.varrazzo@gmail.com>
* psycopg/connection_int.c: dropped notices hack to get COPY errors from * psycopg/connection_int.c: dropped notices hack to get COPY errors from

View File

@ -709,6 +709,7 @@ psyco_conn_cancel(connectionObject *self)
char errbuf[256]; char errbuf[256];
EXC_IF_CONN_CLOSED(self); EXC_IF_CONN_CLOSED(self);
EXC_IF_TPC_PREPARED(self, cancel);
/* do not allow cancellation while the connection is being built */ /* do not allow cancellation while the connection is being built */
Dprintf("psyco_conn_cancel: cancelling with key %p", self->cancel); Dprintf("psyco_conn_cancel: cancelling with key %p", self->cancel);

View File

@ -623,6 +623,12 @@ class ConnectionTwoPhaseTests(unittest.TestCase):
self.assertEqual('transaction-id', xid.gtrid) self.assertEqual('transaction-id', xid.gtrid)
self.assertEqual(None, xid.bqual) self.assertEqual(None, xid.bqual)
def test_cancel_fails_prepared(self):
cnn = self.connect()
cnn.tpc_begin('cancel')
cnn.tpc_prepare()
self.assertRaises(psycopg2.ProgrammingError, cnn.cancel)
decorate_all_tests(ConnectionTwoPhaseTests, skip_if_tpc_disabled) decorate_all_tests(ConnectionTwoPhaseTests, skip_if_tpc_disabled)