Skip to content

Commit afd8ee6

Browse files
authored
Fix missing None-check in get_conversations (#8927)
1 parent 93b1276 commit afd8ee6

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

openhands/server/conversation_manager/standalone_conversation_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ async def attach_to_conversation(
111111
return None
112112
end_time = time.time()
113113
logger.info(
114-
f'ServerConversation {c.sid} connected in {end_time - start_time} seconds'
114+
f'ServerConversation {c.sid} connected in {end_time - start_time} seconds',
115+
extra={'session_id': sid}
115116
)
116117
self._active_conversations[sid] = (c, 1)
117118
return c

openhands/server/routes/conversation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,5 +145,5 @@ async def search_events(
145145
@app.post('/events')
146146
async def add_event(request: Request, conversation: ServerConversation = Depends(get_conversation)):
147147
data = request.json()
148-
conversation_manager.send_to_event_stream(conversation.sid, data)
148+
await conversation_manager.send_to_event_stream(conversation.sid, data)
149149
return JSONResponse({'success': True})

openhands/server/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from fastapi import Depends, Request
1+
from fastapi import Depends, HTTPException, Request, status
22

3+
from openhands.core.logger import openhands_logger as logger
34
from openhands.server.shared import ConversationStoreImpl, config, conversation_manager
45
from openhands.server.user_auth import get_user_id
56
from openhands.storage.conversation.conversation_store import ConversationStore
@@ -24,6 +25,15 @@ async def get_conversation(
2425
conversation = await conversation_manager.attach_to_conversation(
2526
conversation_id, user_id
2627
)
28+
if not conversation:
29+
logger.warn(
30+
f'get_conversation: conversation {conversation_id} not found, attach_to_conversation returned None',
31+
extra={'session_id': conversation_id, 'user_id': user_id},
32+
)
33+
raise HTTPException(
34+
status_code=status.HTTP_404_NOT_FOUND,
35+
detail=f'Conversation {conversation_id} not found',
36+
)
2737
try:
2838
yield conversation
2939
finally:

0 commit comments

Comments
 (0)