From f01f0d587165e573a9cee63589f0c2daeb94a83e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 3 Oct 2015 11:50:56 +0200 Subject: [PATCH] Fix child_of domain on empty MPTT When the MPTT search returns no row, the SQL query generated has an invalid syntax because it uses an empty Or() clause. We replace this empty Or() by a Literal(False) to select nothing. issue5011 review18651002 --- trytond/model/fields/many2one.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/trytond/model/fields/many2one.py b/trytond/model/fields/many2one.py index 8aaf2ce07a..740ea5d058 100644 --- a/trytond/model/fields/many2one.py +++ b/trytond/model/fields/many2one.py @@ -1,7 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. from types import NoneType -from sql import Query, Expression +from sql import Query, Expression, Literal from sql.operators import Or from .field import Field, SQLType @@ -109,6 +109,8 @@ class Many2One(Field): where = Or() for l, r in cursor.fetchall(): where.append((left >= l) & (right <= r)) + if not where: + where = Literal(False) if operator == 'not child_of': return ~where return where