From a2ed58e72dae184f7c43461b36fdf762efb1ce5e Mon Sep 17 00:00:00 2001 From: Adam Holmberg Date: Thu, 22 Jan 2015 09:24:10 -0600 Subject: [PATCH] Improve message on bind type error. Also updated integration/standard/test_types to work in python3 --- cassandra/query.py | 4 ++-- tests/integration/standard/test_types.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cassandra/query.py b/cassandra/query.py index 1b0a56d4..c159e787 100644 --- a/cassandra/query.py +++ b/cassandra/query.py @@ -500,13 +500,13 @@ class BoundStatement(Statement): try: self.values.append(col_type.serialize(value, proto_version)) - except (TypeError, struct.error): + except (TypeError, struct.error) as exc: col_name = col_spec[2] expected_type = col_type actual_type = type(value) message = ('Received an argument of invalid type for column "%s". ' - 'Expected: %s, Got: %s' % (col_name, expected_type, actual_type)) + 'Expected: %s, Got: %s; (%s)' % (col_name, expected_type, actual_type, exc)) raise TypeError(message) return self diff --git a/tests/integration/standard/test_types.py b/tests/integration/standard/test_types.py index b0a47c06..b10f3e6b 100644 --- a/tests/integration/standard/test_types.py +++ b/tests/integration/standard/test_types.py @@ -700,10 +700,10 @@ class TypeTests(unittest.TestCase): self.assertEquals((None, None, None, None), s.execute(read)[0].t) # also test empty strings where compatible - s.execute(insert, [('', None, None, '')]) + s.execute(insert, [('', None, None, b'')]) result = s.execute("SELECT * FROM mytable WHERE k=0") - self.assertEquals(('', None, None, ''), result[0].t) - self.assertEquals(('', None, None, ''), s.execute(read)[0].t) + self.assertEquals(('', None, None, b''), result[0].t) + self.assertEquals(('', None, None, b''), s.execute(read)[0].t) c.shutdown()