diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-11-28 12:15:26 +0000 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-11-28 12:15:26 +0000 |
commit | 0c7b0a943b461d047bdf9db317434d12a8a459dc (patch) | |
tree | e16b7a3503e876b663240ef2b295432734e2e070 | |
parent | 4dbd4344a3c8a920165a969edda06118f7bee6a2 (diff) | |
download | psycopg2-0c7b0a943b461d047bdf9db317434d12a8a459dc.tar.gz |
A prepared connection can't be canceled.
-rw-r--r-- | ChangeLog | 2 | ||||
-rw-r--r-- | psycopg/connection_type.c | 1 | ||||
-rw-r--r-- | tests/test_connection.py | 6 |
3 files changed, 9 insertions, 0 deletions
@@ -2,6 +2,8 @@ * Cancel patch from Jan integrated. + * psycopg/connection_type.c: can't cancel a prepared connection + 2010-11-22 Daniele Varrazzo <daniele.varrazzo@gmail.com> * psycopg/connection_int.c: dropped notices hack to get COPY errors from diff --git a/psycopg/connection_type.c b/psycopg/connection_type.c index e27b312..3469dc2 100644 --- a/psycopg/connection_type.c +++ b/psycopg/connection_type.c @@ -709,6 +709,7 @@ psyco_conn_cancel(connectionObject *self) char errbuf[256]; EXC_IF_CONN_CLOSED(self); + EXC_IF_TPC_PREPARED(self, cancel); /* do not allow cancellation while the connection is being built */ Dprintf("psyco_conn_cancel: cancelling with key %p", self->cancel); diff --git a/tests/test_connection.py b/tests/test_connection.py index 400ddd6..9a28b00 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -623,6 +623,12 @@ class ConnectionTwoPhaseTests(unittest.TestCase): self.assertEqual('transaction-id', xid.gtrid) 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) |