From abb44d5703024fa77eec8a165fc2916cb7534168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 5 May 2012 09:32:24 +0200 Subject: [PATCH] Fix usage of None in search clause review353002 --- trytond/model/fields/property.py | 13 +++++++++---- trytond/model/modelsql.py | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/trytond/model/fields/property.py b/trytond/model/fields/property.py index 05ac36eed2..7dfa64437a 100644 --- a/trytond/model/fields/property.py +++ b/trytond/model/fields/property.py @@ -119,11 +119,13 @@ class Property(Function): break if not default \ - or (clause[2] is False and clause[1] in ['=', '!=']) \ + or ((clause[2] is False or clause[2] is None) + and clause[1] in ['=', '!=']) \ or (clause[1] in ['not like', 'not ilike', 'not in', '!=']): operator = 'in' # default operator - if ((clause[2] is False and clause[1] == '=') - or (clause[2] is not False + if (((clause[2] is False or clause[2] is None) + and clause[1] == '=') + or ((clause[2] is not False and clause[2] is not None) and clause[1] in [ 'not like', 'not ilike', 'not in', '!='])): operator = 'not in' @@ -161,7 +163,8 @@ class Property(Function): operator = operator % '%%s' return ("(CAST(SPLIT_PART(value,',',2) AS %s) IN (" + ",".join((operator,) * len(clause[2])) + ")) ") % sql_type - elif clause[2] is False and clause[1] in ['=', '!=']: + elif ((clause[2] is False or clause[2] is None) + and clause[1] in ['=', '!=']): return "((cast(split_part(value,',',2) as %s) IS NULL " \ ") = %%s) " % sql_type elif clause[1] in ['not like', 'not ilike']: @@ -179,6 +182,8 @@ class Property(Function): res = [] if clause[1] in ('in', 'not in'): res.extend(clause[2]) + elif clause[2] is None: + res.append(False) else: res.append(clause[2]) return res diff --git a/trytond/model/modelsql.py b/trytond/model/modelsql.py index 9f5ab973eb..7c0bfa4ee6 100644 --- a/trytond/model/modelsql.py +++ b/trytond/model/modelsql.py @@ -1554,7 +1554,7 @@ class ModelSQL(ModelStorage): domain[i] = ('id', 'not in', ids2 + _rec_get(ids2, table, domain[i][0])) else: - if isinstance(domain[i][2], bool): + if isinstance(domain[i][2], bool) or domain[i][2] is None: relation_obj = pool.get(field.relation_name) query1 = 'SELECT "' + field.origin + '" ' \ 'FROM "' + relation_obj._table + '" '\