Skip to content

Fix missing None-check in get_conversations #8927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ async def attach_to_conversation(
return None
end_time = time.time()
logger.info(
f'ServerConversation {c.sid} connected in {end_time - start_time} seconds'
f'ServerConversation {c.sid} connected in {end_time - start_time} seconds',
extra={'session_id': sid}
)
self._active_conversations[sid] = (c, 1)
return c
Expand Down
2 changes: 1 addition & 1 deletion openhands/server/routes/conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@ async def search_events(
@app.post('/events')
async def add_event(request: Request, conversation: ServerConversation = Depends(get_conversation)):
data = request.json()
conversation_manager.send_to_event_stream(conversation.sid, data)
await conversation_manager.send_to_event_stream(conversation.sid, data)
return JSONResponse({'success': True})
12 changes: 11 additions & 1 deletion openhands/server/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fastapi import Depends, Request
from fastapi import Depends, HTTPException, Request, status

from openhands.core.logger import openhands_logger as logger
from openhands.server.shared import ConversationStoreImpl, config, conversation_manager
from openhands.server.user_auth import get_user_id
from openhands.storage.conversation.conversation_store import ConversationStore
Expand All @@ -24,6 +25,15 @@ async def get_conversation(
conversation = await conversation_manager.attach_to_conversation(
conversation_id, user_id
)
if not conversation:
logger.warn(
f'get_conversation: conversation {conversation_id} not found, attach_to_conversation returned None',
extra={'session_id': conversation_id, 'user_id': user_id},
)
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f'Conversation {conversation_id} not found',
)
try:
yield conversation
finally:
Expand Down
Loading