mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
Fix for circular import on ConversationValidator (#7583)
This commit is contained in:
@@ -23,7 +23,7 @@ from openhands.server.shared import (
|
||||
sio,
|
||||
)
|
||||
from openhands.storage.conversation.conversation_validator import (
|
||||
ConversationValidatorImpl,
|
||||
create_conversation_validator,
|
||||
)
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ async def connect(connection_id: str, environ):
|
||||
raise ConnectionRefusedError('No conversation_id in query params')
|
||||
|
||||
cookies_str = environ.get('HTTP_COOKIE', '')
|
||||
conversation_validator = ConversationValidatorImpl()
|
||||
conversation_validator = create_conversation_validator()
|
||||
user_id, github_user_id = await conversation_validator.validate(
|
||||
conversation_id, cookies_str
|
||||
)
|
||||
|
||||
@@ -10,8 +10,12 @@ class ConversationValidator:
|
||||
return None, None
|
||||
|
||||
|
||||
conversation_validator_cls = os.environ.get(
|
||||
'OPENHANDS_CONVERSATION_VALIDATOR_CLS',
|
||||
'openhands.storage.conversation.conversation_validator.ConversationValidator',
|
||||
)
|
||||
ConversationValidatorImpl = get_impl(ConversationValidator, conversation_validator_cls)
|
||||
def create_conversation_validator():
|
||||
conversation_validator_cls = os.environ.get(
|
||||
'OPENHANDS_CONVERSATION_VALIDATOR_CLS',
|
||||
'openhands.storage.conversation.conversation_validator.ConversationValidator',
|
||||
)
|
||||
ConversationValidatorImpl = get_impl(
|
||||
ConversationValidator, conversation_validator_cls
|
||||
)
|
||||
return ConversationValidatorImpl()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import importlib
|
||||
from functools import lru_cache
|
||||
from typing import Type, TypeVar
|
||||
|
||||
T = TypeVar('T')
|
||||
@@ -13,6 +14,7 @@ def import_from(qual_name: str):
|
||||
return result
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def get_impl(cls: Type[T], impl_name: str | None) -> Type[T]:
|
||||
"""Import a named implementation of the specified class"""
|
||||
if impl_name is None:
|
||||
|
||||
Reference in New Issue
Block a user