[PR #20241] [CLOSED] fix: Knowledge Base not visible when shared with multiple groups #48564

Closed
opened 2026-04-30 00:34:56 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/20241
Author: @Classic298
Created: 12/29/2025
Status: Closed

Base: devHead: fix-access-control


📝 Commits (1)

  • 09e3ec2 fix: SQLite JSON contains query for multi-group Knowledge Base visibility (#137)

📊 Changes

1 file changed (+14 additions, -13 deletions)

View changed files

📝 backend/open_webui/utils/db/access_control.py (+14 -13)

📄 Description

Summary

  • Fix SQLite JSON array contains check failing when Knowledge Base is shared with multiple groups
  • Replace broken .contains() with EXISTS + json_each() pattern using parameterized queries

Problem

When a Knowledge Base was shared with multiple groups (e.g., Group B and Group C), users belonging to those groups couldn't see it. Sharing with a single group worked correctly.

The root cause was SQLAlchemy's .contains([gid]) not working correctly with SQLite's JSON columns when the array has multiple items.

Solution

Use SQLite's json_each() table-valued function with EXISTS subquery, matching the pattern already used in models/chats.py. This properly checks if a value exists in a JSON array.

Fixes #20229, https://github.com/open-webui/open-webui/issues/20124

Test plan

  • Create a user belonging to multiple groups (Group B and Group C)
  • Create a Knowledge Base shared with both Group B and Group C
  • Verify the Knowledge Base is visible to the user
  • Verify sharing with a single group still works
  • Verify PostgreSQL is unaffected (uses existing JSONB contains)

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/20241 **Author:** [@Classic298](https://github.com/Classic298) **Created:** 12/29/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `fix-access-control` --- ### 📝 Commits (1) - [`09e3ec2`](https://github.com/open-webui/open-webui/commit/09e3ec29b934837580b555bf9b5fe8aab67a64cb) fix: SQLite JSON contains query for multi-group Knowledge Base visibility (#137) ### 📊 Changes **1 file changed** (+14 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/db/access_control.py` (+14 -13) </details> ### 📄 Description ## Summary - Fix SQLite JSON array contains check failing when Knowledge Base is shared with multiple groups - Replace broken `.contains()` with `EXISTS` + `json_each()` pattern using parameterized queries ## Problem When a Knowledge Base was shared with multiple groups (e.g., Group B and Group C), users belonging to those groups couldn't see it. Sharing with a single group worked correctly. The root cause was SQLAlchemy's `.contains([gid])` not working correctly with SQLite's JSON columns when the array has multiple items. ## Solution Use SQLite's `json_each()` table-valued function with `EXISTS` subquery, matching the pattern already used in `models/chats.py`. This properly checks if a value exists in a JSON array. Fixes #20229, https://github.com/open-webui/open-webui/issues/20124 ## Test plan - Create a user belonging to multiple groups (Group B and Group C) - Create a Knowledge Base shared with both Group B and Group C - Verify the Knowledge Base is visible to the user - Verify sharing with a single group still works - Verify PostgreSQL is unaffected (uses existing JSONB contains) ### Contributor License Agreement 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-30 00:34:56 -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#48564