fix(api): ClickHouse decorrelate error on /v3/groups/list - #580
Merged
jacoby149 merged 3 commits intoAug 12, 2026
Conversation
…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.
…ist-clickhouse-window-error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the 500 error on
/v3/groups/list(and/v3/groups/manages) caused by ClickHouse error 48:Root cause: Both
get_user_groupsandget_groups_managesused a correlated scalar subquery withQUALIFY row_number() OVER()to computemember_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(), rewroteget_user_groupsandget_groups_managesapi/tests/test_v3_clickhouse.py— updated mocks for two-query approachapi/tests/test_v3_endpoints.py— updated mocks for two-query approachCHANGELOG.md— 3.0.30 entryAll 40 group-related tests pass.