Fix: Use WHERE instead of HAVING for min_count filter in list_tags()

HAVING requires GROUP BY; count_subq is a correlated scalar subquery, not
an aggregate, so PostgreSQL rejects it. WHERE works correctly and the
integration tests used SQLite which is permissive about this rule.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 18:42:50 +00:00
parent 355014f975
commit 265b967f6b

View File

@@ -90,7 +90,7 @@ class TagRepository:
if prefix: if prefix:
query = query.where(Tag.name.like(f"{prefix}%")) query = query.where(Tag.name.like(f"{prefix}%"))
if min_count > 0: if min_count > 0:
query = query.having(count_subq >= min_count) query = query.where(count_subq >= min_count)
total_query = select(func.count()).select_from(query.subquery()) total_query = select(func.count()).select_from(query.subquery())
total_result = await self._session.execute(total_query) total_result = await self._session.execute(total_query)