Fix password type to allow saving a null password.
This commit is contained in:
@@ -143,6 +143,9 @@ class PasswordType(types.TypeDecorator, ScalarCoercible):
|
|||||||
return Password(value, self.context)
|
return Password(value, self.context)
|
||||||
|
|
||||||
def _coerce(self, value):
|
def _coerce(self, value):
|
||||||
|
if value is None:
|
||||||
|
return
|
||||||
|
|
||||||
if not isinstance(value, Password):
|
if not isinstance(value, Password):
|
||||||
# Hash the password using the default scheme.
|
# Hash the password using the default scheme.
|
||||||
value = self.context.encrypt(value).encode('utf8')
|
value = self.context.encrypt(value).encode('utf8')
|
||||||
|
@@ -100,3 +100,17 @@ class TestPasswordType(TestCase):
|
|||||||
|
|
||||||
# Not sure what to assert here; the test raised an error before.
|
# Not sure what to assert here; the test raised an error before.
|
||||||
assert obj.password != other.password
|
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
|
||||||
|
Reference in New Issue
Block a user