mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 20:35:19 +00:00
fix(chats): fix chat search crash (#18576)
* fix(chats): handle null bytes in PostgreSQL search Removes null bytes from message content before performing case-insensitive search in PostgreSQL, preventing conversion errors and ensuring reliable query results. * fix(chats): prevent null byte errors in PostgreSQL queries Ensures chat content and titles containing null bytes are excluded from PostgreSQL text queries to avoid conversion errors. Improves reliability of search and filtering by handling problematic characters in JSON fields.
This commit is contained in:
parent
cabbdd719b
commit
8da4e5bb19
1 changed files with 7 additions and 2 deletions
|
|
@ -765,15 +765,20 @@ class ChatTable:
|
|||
)
|
||||
|
||||
elif dialect_name == "postgresql":
|
||||
# PostgreSQL relies on proper JSON query for search
|
||||
# PostgreSQL doesn't allow null bytes in text. We filter those out by checking
|
||||
# the JSON representation for \u0000 before attempting text extraction
|
||||
postgres_content_sql = (
|
||||
"EXISTS ("
|
||||
" SELECT 1 "
|
||||
" FROM json_array_elements(Chat.chat->'messages') AS message "
|
||||
" WHERE LOWER(message->>'content') LIKE '%' || :content_key || '%'"
|
||||
" WHERE message->'content' IS NOT NULL "
|
||||
" AND (message->'content')::text NOT LIKE '%\\u0000%' "
|
||||
" AND LOWER(message->>'content') LIKE '%' || :content_key || '%'"
|
||||
")"
|
||||
)
|
||||
postgres_content_clause = text(postgres_content_sql)
|
||||
# Also filter out chats with null bytes in title
|
||||
query = query.filter(text("Chat.title::text NOT LIKE '%\\x00%'"))
|
||||
query = query.filter(
|
||||
or_(
|
||||
Chat.title.ilike(bindparam("title_key")),
|
||||
|
|
|
|||
Loading…
Reference in a new issue