diff options
| author | Xavier Morel <xmo@odoo.com> | 2019-06-06 13:46:37 +0000 |
|---|---|---|
| committer | Xavier Morel <xmo@odoo.com> | 2019-06-07 08:07:13 +0000 |
| commit | 411abff3880c8b3945e2f3afe963894a2380202d (patch) | |
| tree | 1dbc35d804d2665c506ea84c093ea1142e51c356 /odoo/osv | |
| parent | ace7766971532914234e1cccb2bc7fef9446c14a (diff) | |
[FIX] core: != / not ilike failing to match null records
As odoo makes little difference, one would expect `(field, !=, 'foo')`
or `(field, 'not ilike', 'foo')` to have the same behaviour when field is
empty, and provide the opposite result as the "positive" operators.
However because NULL <OP> <value> returns NULL which is generally
assimilated to false, the sections above would fail to match records
whose field is null (they would match records whose field is *empty*
though).
Fix this by wrapping the operation in a coalesce falling back
to (hopefully) the correct value if the result is null.
See also: odoo/odoo#22879
closes odoo/odoo#33959
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
Diffstat (limited to 'odoo/osv')
| -rw-r--r-- | odoo/osv/expression.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/odoo/osv/expression.py b/odoo/osv/expression.py index f8a1c702758..ebf6c56f628 100644 --- a/odoo/osv/expression.py +++ b/odoo/osv/expression.py @@ -1264,11 +1264,11 @@ class expression(object): column = '%s.%s' % (table_alias, _quote(left)) query = '(%s %s %s)' % (unaccent(column + cast), sql_operator, unaccent(format)) + if (need_wildcard and not right) or (right and operator in NEGATIVE_TERM_OPERATORS): + query = '(%s OR %s."%s" IS NULL)' % (query, table_alias, left) + if need_wildcard: - native_str = pycompat.to_text(right) - if not native_str: - query = '(%s OR %s."%s" IS NULL)' % (query, table_alias, left) - params = ['%%%s%%' % native_str] + params = ['%%%s%%' % pycompat.to_text(right)] else: field = model._fields[left] params = [field.convert_to_column(right, model, validate=False)] |
