storage: make ILike work with None attributes

This commit is contained in:
Frédéric Péters 2014-12-26 15:47:47 +01:00
parent df8cce74f0
commit 946904f753
2 changed files with 6 additions and 3 deletions

View File

@ -302,10 +302,13 @@ def test_select_criteria_ilike():
test.foo = 'bar'
test.store()
test.foo = None # makes sure it doesn't break on None
test.store()
assert len(Foobar.select()) == 50
assert [x.id for x in Foobar.select([st.ILike('foo', 'bar')], order_by='id')] == range(21, 51)
assert [x.id for x in Foobar.select([st.ILike('foo', 'BAR')], order_by='id')] == range(21, 51)
assert [x.id for x in Foobar.select([st.ILike('foo', 'bar')], order_by='id')] == range(21, 50)
assert [x.id for x in Foobar.select([st.ILike('foo', 'BAR')], order_by='id')] == range(21, 50)
def test_store_async():
Foobar.wipe()

View File

@ -150,7 +150,7 @@ class And(Criteria):
class ILike(Criteria):
def build_lambda(self):
return lambda x: self.value.lower() in getattr(x, self.attribute, '').lower()
return lambda x: self.value.lower() in (getattr(x, self.attribute) or '').lower()
def parse_clause(clause):
# creates a callable out of a clause