bmuller / twistar

Twistar is an object-relational mapper (ORM) for Python that uses the Twisted library to provide asynchronous DB interaction.
http://findingscience.com/twistar
Other
132 stars 38 forks source link

twistar.validation.presenceOf is broken #32

Closed erikkaplun closed 11 years ago

erikkaplun commented 11 years ago
class MyModel(DBObject):
    field = None
MyModel.validatesPresenceOf('field')

assert MyModel().isValid()  # succeeds

this is because presenceOf has:

    if getattr(obj, name, "") == "":

but should have:

    if getattr(obj, name, None) is None:

optionally you can add checking for "" depending on how you want to interpret empty strings:

if getattr(obj, name, None) in (None, ""):
bmuller commented 11 years ago

Fixed in 1cd603a - thanks!