From 4389c0cea4c17c6177df5e4b131433f6d646df18 Mon Sep 17 00:00:00 2001 From: Sergey Antropoff Date: Wed, 29 Jul 2026 17:02:23 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20500=20=D0=B2=20/admin/stats:=20GROUP=20BY=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BF=D1=80=D0=B8=D1=87=D0=B8=D0=BD=20unw?= =?UTF-8?q?rap=20=D0=B2=20PostgreSQL.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/stats.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/services/stats.py b/app/services/stats.py index e0656ba..ec455f2 100644 --- a/app/services/stats.py +++ b/app/services/stats.py @@ -141,14 +141,16 @@ async def collect_stats(db: AsyncSession) -> dict[str, Any]: ] if since is not None: filters.append(AuditEvent.created_at >= since) + # One expression for SELECT + GROUP BY (PG rejects duplicate binds as unequal) + reason_key = func.coalesce(reason_col, "unknown") rows = ( await db.execute( select( - func.coalesce(reason_col, "unknown"), + reason_key, func.count(AuditEvent.id), ) .where(*filters) - .group_by(func.coalesce(reason_col, "unknown")) + .group_by(reason_key) .order_by(func.count(AuditEvent.id).desc()) ) ).all()