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:
@@ -457,7 +457,11 @@ class Boolean(Column):
|
|||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
""" Always returns a Python boolean. """
|
""" Always returns a Python boolean. """
|
||||||
value = super(Boolean, self).validate(value)
|
value = super(Boolean, self).validate(value)
|
||||||
return bool(value)
|
|
||||||
|
if value is not None:
|
||||||
|
value = bool(value)
|
||||||
|
|
||||||
|
return value
|
||||||
|
|
||||||
def to_python(self, value):
|
def to_python(self, value):
|
||||||
return self.validate(value)
|
return self.validate(value)
|
||||||
|
|||||||
@@ -99,7 +99,22 @@ class TestBoolDefault(BaseCassEngTestCase):
|
|||||||
tmp2 = self.BoolDefaultValueTest.get(test_id=1)
|
tmp2 = self.BoolDefaultValueTest.get(test_id=1)
|
||||||
self.assertEqual(True, tmp2.stuff)
|
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 TestVarInt(BaseCassEngTestCase):
|
||||||
class VarIntTest(Model):
|
class VarIntTest(Model):
|
||||||
|
|||||||
Reference in New Issue
Block a user