Fix password type to allow saving a null password.

This commit is contained in:
Ryan Leckey
2013-11-04 14:47:13 -08:00
parent ed46d408bd
commit 7428fcb061
2 changed files with 17 additions and 0 deletions

View File

@@ -143,6 +143,9 @@ class PasswordType(types.TypeDecorator, ScalarCoercible):
return Password(value, self.context)
def _coerce(self, value):
if value is None:
return
if not isinstance(value, Password):
# Hash the password using the default scheme.
value = self.context.encrypt(value).encode('utf8')

View File

@@ -100,3 +100,17 @@ class TestPasswordType(TestCase):
# Not sure what to assert here; the test raised an error before.
assert obj.password != other.password
def test_set_none(self):
obj = self.User()
obj.password = None
assert obj.password is None
self.session.add(obj)
self.session.commit()
obj = self.session.query(self.User).get(obj.id)
assert obj.password is None