Skip to content

fix(api): ClickHouse decorrelate error on /v3/groups/list - #580

Merged
jacoby149 merged 3 commits into
devfrom
jacoby149/fix-groups-list-clickhouse-window-error
Aug 12, 2026
Merged

fix(api): ClickHouse decorrelate error on /v3/groups/list#580
jacoby149 merged 3 commits into
devfrom
jacoby149/fix-groups-list-clickhouse-window-error

Conversation

@jacoby149

Copy link
Copy Markdown
Owner

Fixes the 500 error on /v3/groups/list (and /v3/groups/manages) caused by ClickHouse error 48:

Cannot decorrelate query, because 'Window' step is not supported (NOT_IMPLEMENTED)

Root cause: Both get_user_groups and get_groups_manages used a correlated scalar subquery with QUALIFY row_number() OVER() to compute member_count. ClickHouse cannot decorrelate window functions inside correlated subqueries.

Fix: Extracted member count into a separate batched query (_get_group_member_counts) that accepts a list of group IDs and returns counts in a single query. The window function now operates at top level where ClickHouse supports it.

Files changed:

  • api/app/v3/services/clickhouse.py — added \_get_group_member_counts(), rewrote get_user_groups and get_groups_manages
  • api/tests/test_v3_clickhouse.py — updated mocks for two-query approach
  • api/tests/test_v3_endpoints.py — updated mocks for two-query approach
  • CHANGELOG.md — 3.0.30 entry

All 40 group-related tests pass.

…bquery with QUALIFY/window function is not supported. Split member_count into a separate batched query (_get_group_member_counts) so the window function lives at top level. Fixes get_user_groups and get_groups_manages.
@jacoby149
jacoby149 merged commit 7125efe into dev Aug 12, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant