From 1ef8f3331fb5d33d6e35fbbca947ae2109a736cd Mon Sep 17 00:00:00 2001 From: Tyler Hobbs Date: Tue, 15 Jul 2014 17:57:16 -0500 Subject: [PATCH] Return list columns as lists instead of tuples --- CHANGELOG.rst | 5 +++++ cassandra/cqltypes.py | 5 +++-- tests/integration/standard/test_types.py | 6 +++--- tests/unit/test_marshalling.py | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6ec090ab..0cc92eaa 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,11 @@ Bug Fixes --------- * Properly specify UDTs for columns in CREATE TABLE statements +Other +----- +* Return list collection columns as python lists instead of tuples + now that tuples are a specific Cassandra type + 2.1.0b1 ======= July 11, 2014 diff --git a/cassandra/cqltypes.py b/cassandra/cqltypes.py index c6b0066d..b70ada99 100644 --- a/cassandra/cqltypes.py +++ b/cassandra/cqltypes.py @@ -714,7 +714,7 @@ class _SimpleParameterizedType(_ParameterizedType): class ListType(_SimpleParameterizedType): typename = 'list' num_subtypes = 1 - adapter = tuple + adapter = list class SetType(_SimpleParameterizedType): @@ -848,7 +848,8 @@ class UserType(TupleType): 'cassname': cls.cassname, 'typename': udt_name, 'fieldnames': field_names, - 'keyspace': keyspace}) + 'keyspace': keyspace, + 'mapped_class': None}) @classmethod def cql_parameterized_type(cls): diff --git a/tests/integration/standard/test_types.py b/tests/integration/standard/test_types.py index 8d11ba10..0b19c5d1 100644 --- a/tests/integration/standard/test_types.py +++ b/tests/integration/standard/test_types.py @@ -203,7 +203,7 @@ class TypeTests(unittest.TestCase): 1.25, # float "1.2.3.4", # inet 12345, # int - ('a', 'b', 'c'), # list collection + ['a', 'b', 'c'], # list collection sortedset((1, 2, 3)), # set collection {'a': 1, 'b': 2}, # map collection "text", # text @@ -280,11 +280,11 @@ class TypeTests(unittest.TestCase): s.execute("INSERT INTO mytable (a, b, c, o, s, l, n) VALUES ('a', 'b', %s, %s, %s, %s, %s)", ('', '', '', [''], {'': 3})) self.assertEqual( - {'c': '', 'o': '', 's': '', 'l': ('', ), 'n': OrderedDict({'': 3})}, + {'c': '', 'o': '', 's': '', 'l': [''], 'n': OrderedDict({'': 3})}, s.execute("SELECT c, o, s, l, n FROM mytable WHERE a='a' AND b='b'")[0]) self.assertEqual( - {'c': '', 'o': '', 's': '', 'l': ('', ), 'n': OrderedDict({'': 3})}, + {'c': '', 'o': '', 's': '', 'l': [''], 'n': OrderedDict({'': 3})}, s.execute(s.prepare("SELECT c, o, s, l, n FROM mytable WHERE a='a' AND b='b'"), [])[0]) # non-string types shouldn't accept empty strings diff --git a/tests/unit/test_marshalling.py b/tests/unit/test_marshalling.py index 685eaf56..16299fc2 100644 --- a/tests/unit/test_marshalling.py +++ b/tests/unit/test_marshalling.py @@ -81,9 +81,9 @@ marshalled_value_pairs = ( (b'', 'ListType(FloatType)', None), (b'', 'SetType(LongType)', None), (b'\x00\x00', 'MapType(DecimalType, BooleanType)', OrderedDict()), - (b'\x00\x00', 'ListType(FloatType)', ()), + (b'\x00\x00', 'ListType(FloatType)', []), (b'\x00\x00', 'SetType(IntegerType)', sortedset()), - (b'\x00\x01\x00\x10\xafYC\xa3\xea<\x11\xe1\xabc\xc4,\x03"y\xf0', 'ListType(TimeUUIDType)', (UUID(bytes=b'\xafYC\xa3\xea<\x11\xe1\xabc\xc4,\x03"y\xf0'),)), + (b'\x00\x01\x00\x10\xafYC\xa3\xea<\x11\xe1\xabc\xc4,\x03"y\xf0', 'ListType(TimeUUIDType)', [UUID(bytes=b'\xafYC\xa3\xea<\x11\xe1\xabc\xc4,\x03"y\xf0')]), ) ordered_dict_value = OrderedDict()