summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--psycopg/connection_type.c1
-rw-r--r--tests/test_connection.py6
3 files changed, 9 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 6c4010c..a9c1531 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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)