[IMP] ORM: Coalesce NULL boolean values to false when generating ORDER BY

After commit f28be81, boolean columns may have more
NULL entries than before. In the (rare) cases where
a boolean column was used for an ORDER clause
(e.g. in the /shop page of website_sale), this
causes a change of the resulting ordering.

By coalescing NULL values to false in SQL,
we make the ordering consistent with what the
framework does for domain expressions with booleans,
and when reading boolean values, that is, NULL is
the same as False.
This commit is contained in:
Olivier Dony 2014-08-12 12:07:10 +02:00
parent 8c7519ccad
commit 3f91f85f60
1 changed files with 3 additions and 0 deletions

View File

@ -4420,6 +4420,7 @@ class BaseModel(object):
order_split = order_part.strip().split(' ')
order_field = order_split[0].strip()
order_direction = order_split[1].strip() if len(order_split) == 2 else ''
order_column = None
inner_clause = None
if order_field == 'id':
order_by_elements.append('"%s"."%s" %s' % (self._table, order_field, order_direction))
@ -4442,6 +4443,8 @@ class BaseModel(object):
continue # ignore non-readable or "non-joinable" fields
else:
raise ValueError( _("Sorting field %s not found on model %s") %( order_field, self._name))
if order_column and order_column._type == 'boolean':
inner_clause = "COALESCE(%s, false)" % inner_clause
if inner_clause:
if isinstance(inner_clause, list):
for clause in inner_clause: