Merge pull request #289 from lchi/lc_ah_bool_validation_288

Prevent Boolean column validation from coercing None to False
This commit is contained in:
Jon Haddad
2014-11-14 11:07:42 -08:00
2 changed files with 20 additions and 1 deletions

View File

@@ -457,7 +457,11 @@ class Boolean(Column):
def validate(self, value):
""" Always returns a Python boolean. """
value = super(Boolean, self).validate(value)
return bool(value)
if value is not None:
value = bool(value)
return value
def to_python(self, value):
return self.validate(value)

View File

@@ -99,7 +99,22 @@ class TestBoolDefault(BaseCassEngTestCase):
tmp2 = self.BoolDefaultValueTest.get(test_id=1)
self.assertEqual(True, tmp2.stuff)
class TestBoolValidation(BaseCassEngTestCase):
class BoolValidationTest(Model):
__keyspace__ = 'test'
test_id = Integer(primary_key=True)
bool_column = Boolean()
@classmethod
def setUpClass(cls):
super(TestBoolValidation, cls).setUpClass()
sync_table(cls.BoolValidationTest)
def test_validation_preserves_none(self):
test_obj = self.BoolValidationTest(test_id=1)
test_obj.validate()
self.assertIsNone(test_obj.bool_column)
class TestVarInt(BaseCassEngTestCase):
class VarIntTest(Model):