Do not use Literal to count in SQL

The * is not actually a parameter of the aggregate function so it is better to
let python-sql manage it with its default value.
This commit is contained in:
Cédric Krier
2025-12-25 09:47:23 +01:00
parent 4ab7069dab
commit 7fb5a4a3de
19 changed files with 33 additions and 39 deletions
+3 -3
View File
@@ -1085,7 +1085,7 @@ class Account(
types = [None]
for name in names:
if name == 'line_count':
columns.append(Count(Literal('*')))
columns.append(Count())
types.append(None)
else:
columns.append(
@@ -1593,7 +1593,7 @@ class AccountParty(ActivePeriodMixin, ModelSQL):
types = [None, None]
for name in names:
if name == 'line_count':
columns.append(Count(Literal('*')).as_(name))
columns.append(Count().as_(name))
types.append(None)
else:
columns.append(Sum(Coalesce(Column(line, name), 0)).as_(name))
@@ -1721,7 +1721,7 @@ class AccountDeferral(ModelSQL, ModelView):
.join(period, condition=move.period == period.id)
.select(
move_line.account, period.fiscalyear,
Count(Literal('*')).as_('line_count'),
Count().as_('line_count'),
group_by=[move_line.account, period.fiscalyear]))
cursor.execute(*deferral.update(
[deferral.line_count], [counting_query.line_count],
+1 -1
View File
@@ -53,7 +53,7 @@ exclude = ['doc']
[tool.hatch.metadata.hooks.tryton]
dependencies = [
'python-dateutil',
'python-sql >= 0.7',
'python-sql >= 1.4',
'simpleeval',
]
copyright = 'COPYRIGHT'