Skip to content

Commit bfb24af

Browse files
committed
use as_text_type kwarg for conversion
1 parent a2b2508 commit bfb24af

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,10 +1435,8 @@ def as_cql_query(self):
14351435
index_target,
14361436
class_name)
14371437
if options:
1438-
opts_cql_encoded = _encoder.cql_encode_all_types(options)
1439-
# PYTHON-1008
1440-
if isinstance(opts_cql_encoded, six.binary_type):
1441-
opts_cql_encoded = opts_cql_encoded.decode('utf-8')
1438+
# PYTHON-1008: `ret` will always be a unicode
1439+
opts_cql_encoded = _encoder.cql_encode_all_types(options, as_text_type=True)
14421440
ret += " WITH OPTIONS = %s" % opts_cql_encoded
14431441
return ret
14441442

0 commit comments

Comments
 (0)