fix(query): ensure aggregate queries without group_by trigger postgres sort normalization

This commit is contained in:
AarDG10 2026-01-14 19:21:24 +05:30
parent 50e675f009
commit fd5da930f3

View file

@ -315,6 +315,10 @@ class Engine:
if for_update:
self.query = self.query.for_update(skip_locked=skip_locked, nowait=not wait)
if any(isinstance(f, functions.AggregateFunction) for f in getattr(self, "fields", [])):
# check if any field in select is aggregated (done to prevent breaking queries in postgres due to order by rule)
self.is_aggregate_query = True
if group_by:
self.is_aggregate_query = True # for postgres (group by used with order by)
self.apply_group_by(group_by)