fix: some older chats fail on every new message with "'NoneType' object is not iterable" (#35390)

After upgrading to 0.13.5, some older chats fail on every new message with `'NoneType' object is not iterable` and the model is never asked. The upgrade keeps each earlier message exactly as it was stored, so a message saved with no value in its attachment field now hands that missing value back, and sending broke on it. A missing attachment value now counts as no attachments, so these chats work again without touching the database.

Fixes #35359
This commit is contained in:
Classic298 authored and GitHub committed 2026-12-01 00:06:05 +04:00
1 parent e771f3eb75
commit 9985caee57
1 file changed
+3 -3
+3 -3
View File
@@ -1632,7 +1632,7 @@ def get_images_from_messages(message_list):
for message in reversed(message_list):
message_images = []
for file in message.get('files', []):
for file in message.get('files') or []:
if file.get('type') == 'image':
message_images.append(file.get('url'))
elif is_raster_image_content_type(file.get('content_type')):
@@ -1683,7 +1683,7 @@ def add_file_context(messages: list) -> list:
# Notes, collections, and chats can be addressed by ID without a URL.
attached_files = [
file
for file in message.get('files', [])
for file in message.get('files') or []
if isinstance(file, dict)
and (
(isinstance(file.get('url'), str) and file['url'] and not file['url'].startswith('data:'))
@@ -2379,7 +2379,7 @@ async def process_chat_payload(request, form_data, user, metadata, model):
for message in form_data['messages']:
image_files = [
f
for f in message.get('files', [])
for f in message.get('files') or []
if f.get('type') == 'image' or is_raster_image_content_type(f.get('content_type'))
]
if message.get('role') == 'user' and image_files: