π OpenHands: AI-Driven Development
fix(backend): unable to export conversation (#12577)
Hiep Le52e39e5d12b4
diff --git a/openhands/app_server/app_conversation/live_status_app_conversation_service.py b/openhands/app_server/app_conversation/live_status_app_conversation_service.pyindex c3d2d81c58..f91ebc8d94 100644--- a/openhands/app_server/app_conversation/live_status_app_conversation_service.py+++ b/openhands/app_server/app_conversation/live_status_app_conversation_service.py@@ -1295,7 +1295,7 @@ class LiveStatusAppConversationService(AppConversationServiceBase):# Get all events for this conversationi = 0async for event in page_iterator(- self.event_service.search_events, conversation_id__eq=conversation_id+ self.event_service.search_events, conversation_id=conversation_id):event_filename = f'event_{i:06d}_{event.id}.json'event_path = os.path.join(temp_dir, event_filename)diff --git a/tests/unit/app_server/test_live_status_app_conversation_service.py b/tests/unit/app_server/test_live_status_app_conversation_service.pyindex 98b0d88aaa..3535425bdf 100644--- a/tests/unit/app_server/test_live_status_app_conversation_service.py+++ b/tests/unit/app_server/test_live_status_app_conversation_service.py@@ -1165,6 +1165,50 @@ class TestLiveStatusAppConversationService:)self.mock_event_service.search_events.assert_called_once()+ @pytest.mark.asyncio+ async def test_export_conversation_calls_search_events_with_correct_parameter_name(+ self,+ ):+ """Test that export_conversation calls search_events with 'conversation_id' parameter, not 'conversation_id__eq'.++ This test verifies the fix for a bug where page_iterator was called with+ conversation_id__eq instead of conversation_id, causing a TypeError since+ the search_events method expects conversation_id as its parameter name.+ """+ # Arrange+ conversation_id = uuid4()++ # Mock conversation info+ mock_conversation_info = Mock(spec=AppConversationInfo)+ mock_conversation_info.id = conversation_id+ mock_conversation_info.model_dump_json = Mock(return_value='{}')++ self.mock_app_conversation_info_service.get_app_conversation_info = AsyncMock(+ return_value=mock_conversation_info+ )++ # Mock empty event page to simplify test+ mock_event_page = Mock()+ mock_event_page.items = []+ mock_event_page.next_page_id = None++ self.mock_event_service.search_events = AsyncMock(return_value=mock_event_page)++ # Act+ await self.service.export_conversation(conversation_id)++ # Assert - Verify search_events was called with 'conversation_id', not 'conversation_id__eq'+ self.mock_event_service.search_events.assert_called()+ call_kwargs = self.mock_event_service.search_events.call_args[1]++ assert 'conversation_id' in call_kwargs, (+ "search_events should be called with 'conversation_id' parameter"+ )+ assert 'conversation_id__eq' not in call_kwargs, (+ "search_events should NOT be called with 'conversation_id__eq' parameter"+ )+ assert call_kwargs['conversation_id'] == conversation_id+@pytest.mark.asyncioasync def test_export_conversation_large_pagination(self):"""Test download with multiple pages of events."""