Skip to content

Commit c75fd19

Browse files
authored
Merge pull request datastax#984 from datastax/python-1008
PYTHON-1008
2 parents 3a1790b + bfb24af commit c75fd19

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Bug Fixes
55
---------
66
* Improve and fix socket error-catching code in nonblocking-socket reactors (PYTHON-1024)
7+
* Non-ASCII characters in schema break CQL string generation (PYTHON-1008)
78

89
Other
910
-----

cassandra/encoder.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,15 @@ def cql_encode_set_collection(self, val):
224224
"""
225225
return '{%s}' % ', '.join(self.mapping.get(type(v), self.cql_encode_object)(v) for v in val)
226226

227-
def cql_encode_all_types(self, val):
227+
def cql_encode_all_types(self, val, as_text_type=False):
228228
"""
229229
Converts any type into a CQL string, defaulting to ``cql_encode_object``
230230
if :attr:`~Encoder.mapping` does not contain an entry for the type.
231231
"""
232-
return self.mapping.get(type(val), self.cql_encode_object)(val)
232+
encoded = self.mapping.get(type(val), self.cql_encode_object)(val)
233+
if as_text_type and not isinstance(encoded, six.text_type):
234+
return encoded.decode('utf-8')
235+
return encoded
233236

234237
if six.PY3:
235238
def cql_encode_ipaddress(self, val):

cassandra/metadata.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,9 @@ def as_cql_query(self):
14351435
index_target,
14361436
class_name)
14371437
if options:
1438-
ret += " WITH OPTIONS = %s" % Encoder().cql_encode_all_types(options)
1438+
# PYTHON-1008: `ret` will always be a unicode
1439+
opts_cql_encoded = _encoder.cql_encode_all_types(options, as_text_type=True)
1440+
ret += " WITH OPTIONS = %s" % opts_cql_encoded
14391441
return ret
14401442

14411443
def export_as_string(self):

tests/unit/test_metadata.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import unittest # noqa
1919

2020
from binascii import unhexlify
21+
import logging
2122
from mock import Mock
2223
import os
2324
import six
@@ -38,6 +39,9 @@
3839
from cassandra.pool import Host
3940

4041

42+
log = logging.getLogger(__name__)
43+
44+
4145
class StrategiesTest(unittest.TestCase):
4246

4347
@classmethod
@@ -536,9 +540,12 @@ def test_column_name_multiple_partition(self):
536540

537541
def test_index(self):
538542
im = IndexMetadata(self.name, self.name, self.name, kind='', index_options={'target': self.name})
539-
im.export_as_string()
543+
log.debug(im.export_as_string())
540544
im = IndexMetadata(self.name, self.name, self.name, kind='CUSTOM', index_options={'target': self.name, 'class_name': 'Class'})
541-
im.export_as_string()
545+
log.debug(im.export_as_string())
546+
# PYTHON-1008
547+
im = IndexMetadata(self.name, self.name, self.name, kind='CUSTOM', index_options={'target': self.name, 'class_name': 'Class', 'delimiter': self.name})
548+
log.debug(im.export_as_string())
542549

543550
def test_function(self):
544551
fm = Function(self.name, self.name, (u'int', u'int'), (u'x', u'y'), u'int', u'language', self.name, False)

0 commit comments

Comments
 (0)