Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Fix for issue with user id (#6320)

tofarreff9e072728b
diff --git a/openhands/storage/conversation/file_conversation_store.py b/openhands/storage/conversation/file_conversation_store.py
index a9682c35c8..249374c524 100644
--- a/openhands/storage/conversation/file_conversation_store.py
+++ b/openhands/storage/conversation/file_conversation_store.py
@@ -1,5 +1,6 @@
from __future__ import annotations
+import json
from dataclasses import dataclass
from pathlib import Path
@@ -36,7 +37,13 @@ class FileConversationStore(ConversationStore):
async def get_metadata(self, conversation_id: str) -> ConversationMetadata:
path = self.get_conversation_metadata_filename(conversation_id)
json_str = await call_sync_from_async(self.file_store.read, path)
- result = conversation_metadata_type_adapter.validate_json(json_str)
+
+ # Temp: force int to str to stop pydandic being, well... pedantic
+ json_obj = json.loads(json_str)
+ if isinstance(json_obj.get('github_user_id'), int):
+ json_obj['github_user_id'] = str(json_obj.get('github_user_id'))
+
+ result = conversation_metadata_type_adapter.validate_python(json_obj)
return result
async def delete_metadata(self, conversation_id: str) -> None:
diff --git a/tests/unit/test_file_conversation_store.py b/tests/unit/test_file_conversation_store.py
new file mode 100644
index 0000000000..323f20de77
--- /dev/null
+++ b/tests/unit/test_file_conversation_store.py
@@ -0,0 +1,42 @@
+import json
+
+import pytest
+
+from openhands.storage.conversation.file_conversation_store import FileConversationStore
+from openhands.storage.data_models.conversation_metadata import ConversationMetadata
+from openhands.storage.memory import InMemoryFileStore
+
+
+async def test_load_store():
+ store = FileConversationStore(InMemoryFileStore({}))
+ expected = ConversationMetadata(
+ conversation_id='some-conversation-id',
+ github_user_id='some-user-id',
+ selected_repository='some-repo',
+ title="Let's talk about trains",
+ )
+ await store.save_metadata(expected)
+ found = await store.get_metadata('some-conversation-id')
+ assert expected == found
+
+
+async def test_load_int_user_id():
+ store = FileConversationStore(
+ InMemoryFileStore(
+ {
+ 'sessions/some-conversation-id/metadata.json': json.dumps(
+ {
+ 'conversation_id': 'some-conversation-id',
+ 'github_user_id': 12345,
+ 'selected_repository': 'some-repo',
+ 'title': "Let's talk about trains",
+ 'created_at': '2025-01-16T19:51:04.886331Z',
+ }
+ )
+ }
+ )
+ )
+ found = await store.get_metadata('some-conversation-id')
+ assert found.github_user_id == '12345'