Skip to content
Browse files

[FIX] expression: properly handle {TRUE,FALSE}_LEAF

Before this commit, doing expression.OR() with only FALSE_LEAF would
yield [] which is equivalent to TRUE_LEAF and is therefore not correct.

The same happened (to a lesser extent) with expression.AND() within an
expression.OR(), since the former would return a [] which would be
ignored by expression.OR().

See tests for a clearer view of the use cases.

Fixes #30113, #26540
  • Loading branch information...
Elkasitu committed Feb 18, 2019
1 parent 69719f5 commit 289f8a895cb02057fb2d712220f529653f345e19
Showing with 31 additions and 1 deletion.
  1. +30 −0 odoo/addons/base/tests/
  2. +1 −1 odoo/osv/
@@ -612,6 +612,36 @@ def test_lp1071710(self):
not_be = Partner.with_context(lang='fr_FR').search([('country_id', '!=', 'Belgique')])
self.assertNotIn(agrolait, not_be)

def test_proper_combine_unit_leaves(self):
# test that unit leaves (TRUE_LEAF, FALSE_LEAF) are properly handled in specific cases
false = expression.FALSE_DOMAIN
true = expression.TRUE_DOMAIN
normal = [('foo', '=', 'bar')]
# OR with single FALSE_LEAF
expr = expression.OR([false])
self.assertEqual(expr, false)
# OR with multiple FALSE_LEAF
expr = expression.OR([false, false])
self.assertEqual(expr, false)
# OR with FALSE_LEAF and a normal leaf
expr = expression.OR([false, normal])
self.assertEqual(expr, normal)
# OR with AND of single TRUE_LEAF and normal leaf
expr = expression.OR([expression.AND([true]), normal])
self.assertEqual(expr, true)
# AND with single TRUE_LEAF
expr = expression.AND([true])
self.assertEqual(expr, true)
# AND with multiple TRUE_LEAF
expr = expression.AND([true, true])
self.assertEqual(expr, true)
# AND with TRUE_LEAF and normal leaves
expr = expression.AND([true, normal])
self.assertEqual(expr, normal)
# AND with OR with single FALSE_LEAF and normal leaf
expr = expression.AND([expression.OR([false]), normal])
self.assertEqual(expr, false)

class TestAutoJoin(TransactionCase):

@@ -233,7 +233,7 @@ def combine(operator, unit, zero, domains):
result += domain
count += 1
result = [operator] * (count - 1) + result
return result
return result or unit

def AND(domains):

0 comments on commit 289f8a8

Please sign in to comment.
You can’t perform that action at this time.