Исправлен 500 в /admin/stats: GROUP BY для причин unwrap в PostgreSQL.
devops-tools/wrapped/wrapped-build/pipeline/head This commit looks good
devops-tools/wrapped/wrapped-deploy/pipeline/head This commit looks good

This commit is contained in:
Sergey Antropoff
2026-07-29 17:02:23 +03:00
parent f35144ed28
commit 4389c0cea4
+4 -2
View File
@@ -141,14 +141,16 @@ async def collect_stats(db: AsyncSession) -> dict[str, Any]:
] ]
if since is not None: if since is not None:
filters.append(AuditEvent.created_at >= since) 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 = ( rows = (
await db.execute( await db.execute(
select( select(
func.coalesce(reason_col, "unknown"), reason_key,
func.count(AuditEvent.id), func.count(AuditEvent.id),
) )
.where(*filters) .where(*filters)
.group_by(func.coalesce(reason_col, "unknown")) .group_by(reason_key)
.order_by(func.count(AuditEvent.id).desc()) .order_by(func.count(AuditEvent.id).desc())
) )
).all() ).all()