From 0cec7fef76287f710bab39b3bb2888b4621a5ad3 Mon Sep 17 00:00:00 2001 From: Mark Florisson Date: Fri, 7 Aug 2015 12:03:54 +0100 Subject: [PATCH] Some more small bug fixes to Cython-based deserializers --- cassandra/deserializers.pyx | 11 ++++++++++- tests/integration/cqlengine/query/test_queryset.py | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/cassandra/deserializers.pyx b/cassandra/deserializers.pyx index ad1e5d1a..151d7747 100644 --- a/cassandra/deserializers.pyx +++ b/cassandra/deserializers.pyx @@ -95,7 +95,7 @@ cdef class DesInetAddressType(Deserializer): cdef bytes byts = to_bytes(buf) # TODO: optimize inet_ntop, inet_ntoa - if len(buf.size) == 16: + if buf.size == 16: return util.inet_ntop(socket.AF_INET6, byts) else: # util.inet_pton could also handle, but this is faster @@ -162,6 +162,7 @@ cdef class _DesParameterizedType(Deserializer): super().__init__(cqltype) self.subtypes = cqltype.subtypes self.deserializers = make_deserializers(cqltype.subtypes) + self.subtypes_len = len(self.subtypes) cdef class _DesSingleParamType(_DesParameterizedType): @@ -352,6 +353,14 @@ cdef class DesCompositeType(_DesParameterizedType): for i in range(self.subtypes_len): if not buf.size: # CompositeType can have missing elements at the end + + # Fill the tuple with None values and slice it + # + # (I'm not sure a tuple needs to be fully initialized before + # it can be destroyed, so play it safe) + for j in range(i, self.subtypes_len): + tuple_set(res, j, None) + res = res[:i] break element_length = uint16_unpack(buf.ptr) diff --git a/tests/integration/cqlengine/query/test_queryset.py b/tests/integration/cqlengine/query/test_queryset.py index 7bb101b9..45277520 100644 --- a/tests/integration/cqlengine/query/test_queryset.py +++ b/tests/integration/cqlengine/query/test_queryset.py @@ -629,7 +629,7 @@ class TestMinMaxTimeUUIDFunctions(BaseCassEngTestCase): # test kwarg filtering q = TimeUUIDQueryModel.filter(partition=pk, time__lte=functions.MaxTimeUUID(midpoint)) q = [d for d in q] - assert len(q) == 2 + self.assertEqual(len(q), 2, msg="Got: %s" % q) datas = [d.data for d in q] assert '1' in datas assert '2' in datas