From 0c7b0a943b461d047bdf9db317434d12a8a459dc Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 28 Nov 2010 12:15:26 +0000 Subject: [PATCH] A prepared connection can't be canceled. --- ChangeLog | 2 ++ psycopg/connection_type.c | 1 + tests/test_connection.py | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6c4010c7..a9c15313 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 * 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 e27b3120..3469dc2f 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 400ddd62..9a28b00e 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)