Merge pull request #6996 from Peter-De-Ath/fix_get_groups_by_member_id-postgres-sqlite

fix get groups by member id postgres
This commit is contained in:
Timothy Jaeryang Baek 2024-11-17 14:01:15 -08:00 committed by GitHub
commit 17c9a92767
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,7 +11,7 @@ from open_webui.apps.webui.models.files import FileMetadataResponse
from pydantic import BaseModel, ConfigDict
from sqlalchemy import BigInteger, Column, String, Text, JSON
from sqlalchemy import BigInteger, Column, String, Text, JSON, func
log = logging.getLogger(__name__)
@ -128,7 +128,8 @@ class GroupTable:
return [
GroupModel.model_validate(group)
for group in db.query(Group)
.filter(Group.user_ids.contains([user_id]))
.filter(func.json_array_length(Group.user_ids) > 0) # Ensure array exists
.filter(Group.user_ids.cast(String).like(f'%"{user_id}"%')) # String-based check
.order_by(Group.updated_at.desc())
.all()
]