From 8e6a1db2f8ce33b486d671aff479959aa531d4ed Mon Sep 17 00:00:00 2001 From: Alan Boudreault Date: Thu, 25 May 2017 17:34:40 -0400 Subject: [PATCH] PrepareStatement should support is_idempotent --- CHANGELOG.rst | 7 +++++++ cassandra/query.py | 3 ++- tests/integration/standard/test_policies.py | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f7bfc004..5423e039 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,10 @@ +3.11 +==== + +Bug Fixes +--------- +* is_idempotent flag is not propagated from PreparedStatement to BoundStatement (PYTHON-736) + 3.10.0 ====== May 24, 2017 diff --git a/cassandra/query.py b/cassandra/query.py index cfa3aef6..a3dcc1d8 100644 --- a/cassandra/query.py +++ b/cassandra/query.py @@ -496,7 +496,8 @@ class BoundStatement(Statement): self.keyspace = meta[0].keyspace_name Statement.__init__(self, retry_policy, consistency_level, routing_key, - serial_consistency_level, fetch_size, keyspace, custom_payload) + serial_consistency_level, fetch_size, keyspace, custom_payload, + prepared_statement.is_idempotent) def bind(self, values): """ diff --git a/tests/integration/standard/test_policies.py b/tests/integration/standard/test_policies.py index 91f62df6..0503ce3b 100644 --- a/tests/integration/standard/test_policies.py +++ b/tests/integration/standard/test_policies.py @@ -112,6 +112,16 @@ class SpecExecTest(BasicSharedKeyspaceUnitTestCase): with self.assertRaises(OperationTimedOut): result = self.session.execute(statement, execution_profile='spec_ep_rr', timeout=.5) + # PYTHON-736 Test speculation policy works with a prepared statement + statement = self.session.prepare("SELECT timeout(100) FROM d WHERE k = ?") + # non-idempotent + result = self.session.execute(statement, (0,), execution_profile='spec_ep_brr') + self.assertEqual(1, len(result.response_future.attempted_hosts)) + # idempotent + statement.is_idempotent = True + result = self.session.execute(statement, (0,), execution_profile='spec_ep_brr') + self.assertLess(1, len(result.response_future.attempted_hosts)) + #TODO redo this tests with Scassandra def test_speculative_and_timeout(self): """