mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Fix missing None-check in get_conversations (#8927)
This commit is contained in:
parent
93b1276768
commit
afd8ee61e7
@ -111,7 +111,8 @@ class StandaloneConversationManager(ConversationManager):
|
||||
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
|
||||
|
||||
@ -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})
|
||||
|
||||
@ -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
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user