diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4380d2ed..b1f89816 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -35,6 +35,7 @@ Bug Fixes * Fix cassandra.concurrent behavior when dealing with automatic paging (PYTHON-81) * Properly defunct connections after protocol errors +* Avoid UnicodeDecodeError when query string is unicode (PYTHON-76) 2.0.2 ===== diff --git a/cassandra/cluster.py b/cassandra/cluster.py index 847b58ca..fd63f436 100644 --- a/cassandra/cluster.py +++ b/cassandra/cluster.py @@ -1253,8 +1253,10 @@ class Session(object): if isinstance(query, SimpleStatement): query_string = query.query_string + if six.PY2 and isinstance(query_string, six.text_type): + query_string = query_string.encode('utf-8') if parameters: - query_string = bind_params(query.query_string, parameters, self.encoders) + query_string = bind_params(query_string, parameters, self.encoders) message = QueryMessage( query_string, cl, query.serial_consistency_level, fetch_size, timestamp=timestamp) diff --git a/tests/integration/standard/test_types.py b/tests/integration/standard/test_types.py index 08e48383..8d11ba10 100644 --- a/tests/integration/standard/test_types.py +++ b/tests/integration/standard/test_types.py @@ -436,3 +436,10 @@ class TypeTests(unittest.TestCase): prepared = s.prepare("SELECT b FROM mytable WHERE a=?") self.assertEqual(complete, s.execute(prepared, (2,))[0].b) self.assertEqual(partial_result, s.execute(prepared, (3,))[0].b) + + def test_unicode_query_string(self): + c = Cluster(protocol_version=PROTOCOL_VERSION) + s = c.connect() + + query = u"SELECT * FROM system.schema_columnfamilies WHERE keyspace_name = 'ef\u2052ef' AND columnfamily_name = %s" + s.execute(query, (u"fe\u2051fe",))