[PR #22167] [MERGED] fix: add missing group_id filter to analytics token usage query #26527

Closed
opened 2026-04-20 06:33:15 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/22167
Author: @Classic298
Created: 3/2/2026
Status: Merged
Merged: 3/8/2026
Merged by: @tjbck

Base: devHead: fix/analytics-token-usage-group-filter


📝 Commits (1)

  • 6616ff8 fix: add missing group_id filter to analytics token usage query

📊 Changes

2 files changed (+10 additions, -1 deletions)

View changed files

📝 backend/open_webui/models/chat_messages.py (+9 -0)
📝 backend/open_webui/routers/analytics.py (+1 -1)

📄 Description

The get_token_usage_by_user query lacked group_id filtering, while the companion get_message_count_by_user query already supported it. When an admin filtered analytics by user group, message counts were correctly scoped to the group but token usage totals included data from all users.

Add the group_id parameter and subquery filter to get_token_usage_by_user, matching the pattern used by get_message_count_by_user and other analytics queries, and pass group_id through from the analytics endpoint.

Contributor License Agreement

By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/22167 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 3/2/2026 **Status:** ✅ Merged **Merged:** 3/8/2026 **Merged by:** [@tjbck](https://github.com/tjbck) **Base:** `dev` ← **Head:** `fix/analytics-token-usage-group-filter` --- ### 📝 Commits (1) - [`6616ff8`](https://github.com/open-webui/open-webui/commit/6616ff8d51b44054f3a153103c8d44bea11f924e) fix: add missing group_id filter to analytics token usage query ### 📊 Changes **2 files changed** (+10 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/models/chat_messages.py` (+9 -0) 📝 `backend/open_webui/routers/analytics.py` (+1 -1) </details> ### 📄 Description The get_token_usage_by_user query lacked group_id filtering, while the companion get_message_count_by_user query already supported it. When an admin filtered analytics by user group, message counts were correctly scoped to the group but token usage totals included data from all users. Add the group_id parameter and subquery filter to get_token_usage_by_user, matching the pattern used by get_message_count_by_user and other analytics queries, and pass group_id through from the analytics endpoint. ### Contributor License Agreement <!-- 🚨 DO NOT DELETE THE TEXT BELOW 🚨 Keep the "Contributor License Agreement" confirmation text intact. Deleting it will trigger the CLA-Bot to INVALIDATE your PR. --> By submitting this pull request, I confirm that I have read and fully agree to the [Contributor License Agreement (CLA)](https://github.com/open-webui/open-webui/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT), and I am providing my contributions under its terms. > [!NOTE] > Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 06:33:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#26527