diff --git a/backend/open_webui/socket/main.py b/backend/open_webui/socket/main.py index d59ff53277..336f61370b 100644 --- a/backend/open_webui/socket/main.py +++ b/backend/open_webui/socket/main.py @@ -898,8 +898,11 @@ async def _make_channel_emitter(request_info): async def get_event_emitter(request_info, update_db=True): - # Channel mode: route pipeline output to channel message updates - if request_info.get('chat_id', '').startswith('channel:'): + # Channel mode: route pipeline output to channel message updates. + # Use `or ''` because callers may pass chat_id=None (server-to-server API + # callers like tools/automations); dict.get default only kicks in when + # the key is missing entirely. + if (request_info.get('chat_id') or '').startswith('channel:'): return await _make_channel_emitter(request_info) async def __event_emitter__(event_data): @@ -917,7 +920,7 @@ async def get_event_emitter(request_info, update_db=True): room=f'user:{user_id}', ) - if update_db and message_id and not request_info.get('chat_id', '').startswith('local:'): + if update_db and message_id and not (request_info.get('chat_id') or '').startswith('local:'): event_type = event_data.get('type') if event_type == 'status': diff --git a/backend/open_webui/utils/google_drive_client.py b/backend/open_webui/utils/google_drive_client.py index 3ca3048bce..931ca9c033 100644 --- a/backend/open_webui/utils/google_drive_client.py +++ b/backend/open_webui/utils/google_drive_client.py @@ -680,7 +680,7 @@ async def create_drive_client_for_user( from open_webui.models.oauth_sessions import OAuthSessions # Get Google OAuth session - oauth_session = OAuthSessions.get_session_by_provider_and_user_id("google", user_id) + oauth_session = await OAuthSessions.get_session_by_provider_and_user_id("google", user_id) if not oauth_session: log.warning(f"No Google OAuth session for user {user_id}") return None diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index d0b6364e2b..3d7aa2b2a1 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -3060,7 +3060,7 @@ async def background_tasks_handler(ctx): messages = [] if ( - 'chat_id' in metadata + metadata.get('chat_id') and not metadata['chat_id'].startswith('local:') and not metadata['chat_id'].startswith('channel:') ): @@ -3143,8 +3143,8 @@ async def background_tasks_handler(ctx): } ) - if not metadata.get('chat_id', '').startswith('local:') and not metadata.get( - 'chat_id', '' + if not (metadata.get('chat_id') or '').startswith('local:') and not ( + metadata.get('chat_id') or '' ).startswith('channel:'): await Chats.upsert_message_to_chat_by_id_and_message_id( metadata['chat_id'], @@ -3157,9 +3157,9 @@ async def background_tasks_handler(ctx): except Exception as e: pass - if not metadata.get('chat_id', '').startswith('local:') and not metadata.get('chat_id', '').startswith( - 'channel:' - ): # Only update titles and tags for non-temp chats + if not (metadata.get('chat_id') or '').startswith('local:') and not ( + metadata.get('chat_id') or '' + ).startswith('channel:'): # Only update titles and tags for non-temp chats if TASKS.TITLE_GENERATION in tasks: user_message = get_last_user_message(messages) if user_message and len(user_message) > 100: