mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
Fix for issue with user id (#6320)
This commit is contained in:
@@ -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:
|
||||
|
||||
42
tests/unit/test_file_conversation_store.py
Normal file
42
tests/unit/test_file_conversation_store.py
Normal file
@@ -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
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
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'
|
||||
Reference in New Issue
Block a user