Исправлен 500 в /admin/stats: GROUP BY для причин unwrap в PostgreSQL.
This commit is contained in:
@@ -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()
|
||||||
|
|||||||
Reference in New Issue
Block a user