Permalink
Browse files

Raise TypeErr when bad CF attr type is supplied

Fixes #99
  • Loading branch information...
1 parent 103866a commit 0806c6215908d217cc56c524d439edce838b6a14 @thobbs thobbs committed Dec 8, 2011
Showing with 19 additions and 2 deletions.
  1. +10 −1 pycassa/system_manager.py
  2. +9 −1 tests/test_system_manager.py
View
@@ -249,7 +249,16 @@ def _system_add_column_family(self, cfdef):
def _qualify_type_class(self, classname):
if classname:
- s = str(classname)
+ if isinstance(classname, types.CassandraType):
+ s = str(classname)
+ elif isinstance(classname, basestring):
+ s = classname
+ else:
+ raise TypeError(
+ "Column family validators and comparators " \
+ "must be specified as instances of " \
+ "pycassa.types.CassandraType subclasses or strings.")
+
if s.find('.') == -1:
return 'org.apache.cassandra.db.marshal.%s' % s
else:
@@ -1,11 +1,12 @@
import unittest
-from nose.tools import assert_equal
+from nose.tools import assert_equal, assert_raises
from pycassa.pool import ConnectionPool
from pycassa.columnfamily import ColumnFamily
from pycassa.system_manager import *
from pycassa.cassandra.ttypes import InvalidRequestException
+from pycassa.types import LongType
TEST_KS = 'PycassaTestKeyspace'
@@ -40,6 +41,13 @@ def test_system_calls(self):
sys.drop_keyspace('TestKeyspace')
+ def test_bad_comparator(self):
+ sys.create_keyspace('TestKeyspace', SIMPLE_STRATEGY, {'replication_factor': '3'})
+ for comparator in [types.LongType, 123]:
+ assert_raises(TypeError, sys.create_column_family,
+ 'TestKeyspace', 'TestBadCF', comparator_type=comparator)
+ sys.drop_keyspace('TestKeyspace')
+
def test_alter_column_non_bytes_type(self):
sys.create_column_family(TEST_KS, 'LongCF', comparator_type=LONG_TYPE)
sys.create_index(TEST_KS, 'LongCF', 3, LONG_TYPE)

0 comments on commit 0806c62

Please sign in to comment.