NULL value for boolean fields should be considered like False

issue2755
review476002
This commit is contained in:
Cédric Krier committed 2012-08-23 23:17:15 +02:00
1 parent 6cbd42c37b
commit 4dc94980b1
2 files changed
+28 -5

No files matched your search

+11 -5
View File
@@ -1835,15 +1835,21 @@ class ModelSQL(ModelStorage):
else:
if (arg[2] is False or arg[2] is None) and (arg[1] == '='):
if column._type == 'boolean':
qu1.append('("%s"."%s" = %%s)' % \
(table._table, arg[0]))
qu1.append('(("%s"."%s" = %%s) OR ("%s"."%s" IS NULL))'
% (table._table, arg[0], table._table, arg[0]))
qu2.append(False)
else:
qu1.append('("%s"."%s" IS NULL)' % \
(table._table, arg[0]))
elif (arg[2] is False or arg[2] is None) and (arg[1] == '!='):
qu1.append('("%s"."%s" IS NOT NULL)' % \
(table._table, arg[0]))
elif (arg[2] is False or arg[2] is None) and (arg[1] == '!='):
if column._type == 'boolean':
qu1.append('(("%s"."%s" != %%s) '
'AND ("%s"."%s" IS NOT NULL))'
% (table._table, arg[0], table._table, arg[0]))
qu2.append(False)
else:
qu1.append('("%s"."%s" IS NOT NULL)' % \
(table._table, arg[0]))
else:
if arg[0] == 'id':
qu1.append('("%s"."%s" %s %%s)' % \
+17
View File
@@ -170,6 +170,23 @@ class FieldsTestCase(unittest.TestCase):
boolean3_id = self.boolean.create({})
self.assert_(boolean3_id)
# Test search with NULL value
boolean4_id = self.boolean.create({
'boolean': None,
})
self.assert_(boolean4_id)
boolean_ids = self.boolean.search([
('boolean', '=', False),
])
self.assertEqual(boolean_ids,
[boolean2_id, boolean3_id, boolean4_id])
boolean_ids = self.boolean.search([
('boolean', '!=', False),
])
self.assertEqual(boolean_ids, [boolean1_id])
boolean3 = self.boolean.read(boolean3_id, ['boolean'])
self.assert_(boolean3['boolean'] == False)