From 06657b81097b17d101699c75089ec2fde004ae87 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Wed, 11 Mar 2026 20:24:21 +0100 Subject: [PATCH] fix: handle non-dict history/messages in chat_message migration (#22588) Some databases contain chat records where 'history' or 'messages' are stored as lists instead of dicts. This causes an AttributeError ('list' object has no attribute 'items') during the 8452d01d26d7_add_chat_message_table migration. Add isinstance checks to skip chat records with unexpected data shapes gracefully, matching the existing pattern used for individual message validation. --- .../versions/8452d01d26d7_add_chat_message_table.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/open_webui/migrations/versions/8452d01d26d7_add_chat_message_table.py b/backend/open_webui/migrations/versions/8452d01d26d7_add_chat_message_table.py index aa9b0a4c26..fda33d17bf 100644 --- a/backend/open_webui/migrations/versions/8452d01d26d7_add_chat_message_table.py +++ b/backend/open_webui/migrations/versions/8452d01d26d7_add_chat_message_table.py @@ -151,7 +151,12 @@ def upgrade() -> None: continue history = chat_data.get("history", {}) + if not isinstance(history, dict): + continue + messages = history.get("messages", {}) + if not isinstance(messages, dict): + continue for message_id, message in messages.items(): if not isinstance(message, dict):