[FIX] *: ordered group_by for field with capital letters
When doing a group_by in a tree view, and then ordering by an aggregated field which contains at least one capital letter in its name, you will get an error and won't be able to ordery by this field. Why? read_group is called when sorting a group by, which calls _read_group_raw which then goes to call _read_group_prepare, which will return order by terms in this manner ['id asc', 'x_Test desc'] the problem with this is that postgres automatically converts non-quoted/non-qualified column name to lowercase, of course this means that if we have a field "x_Test" but no field "x_test", it will try to look up "x_test" instead of "x_Test" and since the column doesn't exist, it will throw a ProgrammingError. This commit changes this behavior by wrapping the order_by terms generated in _read_group_prepare with double quotes, which postgres interprets correctly. Fixes #21348
This commit is contained in:
+2
-1
@@ -1914,7 +1914,8 @@ class BaseModel(object):
|
||||
order = '"%s" %s' % (order_field, '' if len(order_split) == 1 else order_split[1])
|
||||
orderby_terms.append(order)
|
||||
elif order_field in aggregated_fields:
|
||||
orderby_terms.append(order_part)
|
||||
order_split[0] = '"' + order_field + '"'
|
||||
orderby_terms.append(' '.join(order_split))
|
||||
else:
|
||||
# Cannot order by a field that will not appear in the results (needs to be grouped or aggregated)
|
||||
_logger.warn('%s: read_group order by `%s` ignored, cannot sort on empty columns (not grouped/aggregated)',
|
||||
|
||||
Reference in New Issue
Block a user