Skip to content

πŸ™Œ OpenHands: AI-Driven Development

Add missing `SqlAlchemy` type stub to mypy (#13413)

Rohit Malhotra7bc3300981fa
diff --git a/dev_config/python/.pre-commit-config.yaml b/dev_config/python/.pre-commit-config.yaml
index f55569b7c0..582223aba3 100644
--- a/dev_config/python/.pre-commit-config.yaml
+++ b/dev_config/python/.pre-commit-config.yaml
@@ -60,6 +60,7 @@ repos:
lxml,
"openhands-sdk==1.17.0",
"openhands-tools==1.17.0",
+ "sqlalchemy>=2.0",
]
# To see gaps add `--html-report mypy-report/`
entry: mypy --config-file dev_config/python/mypy.ini openhands/
diff --git a/enterprise/dev_config/python/.pre-commit-config.yaml b/enterprise/dev_config/python/.pre-commit-config.yaml
index 231832386d..1aa57149f0 100644
--- a/enterprise/dev_config/python/.pre-commit-config.yaml
+++ b/enterprise/dev_config/python/.pre-commit-config.yaml
@@ -50,6 +50,7 @@ repos:
- ./
- stripe==11.5.0
- pygithub==2.6.1
+ - sqlalchemy>=2.0
# Use -p (package) to avoid dual module name conflict when using MYPYPATH
# MYPYPATH=enterprise allows resolving bare imports like "from integrations.xxx"
# Note: tests package excluded to avoid conflict with core openhands tests
diff --git a/openhands/app_server/app_conversation/sql_app_conversation_info_service.py b/openhands/app_server/app_conversation/sql_app_conversation_info_service.py
index 6abf52112e..fa60e890fb 100644
--- a/openhands/app_server/app_conversation/sql_app_conversation_info_service.py
+++ b/openhands/app_server/app_conversation/sql_app_conversation_info_service.py
@@ -524,19 +524,19 @@ class SQLAppConversationInfoService(AppConversationInfoService):
sandbox_id = stored.sandbox_id
assert sandbox_id is not None
- # Rebuild token usage
+ # Rebuild token usage (use 0 as default for nullable int columns)
token_usage = TokenUsage(
- prompt_tokens=stored.prompt_tokens,
- completion_tokens=stored.completion_tokens,
- cache_read_tokens=stored.cache_read_tokens,
- cache_write_tokens=stored.cache_write_tokens,
- context_window=stored.context_window,
- per_turn_token=stored.per_turn_token,
+ prompt_tokens=stored.prompt_tokens or 0,
+ completion_tokens=stored.completion_tokens or 0,
+ cache_read_tokens=stored.cache_read_tokens or 0,
+ cache_write_tokens=stored.cache_write_tokens or 0,
+ context_window=stored.context_window or 0,
+ per_turn_token=stored.per_turn_token or 0,
)
- # Rebuild metrics object
+ # Rebuild metrics object (use 0.0 as default for nullable float columns)
metrics = MetricsSnapshot(
- accumulated_cost=stored.accumulated_cost,
+ accumulated_cost=stored.accumulated_cost or 0.0,
max_budget_per_task=stored.max_budget_per_task,
accumulated_token_usage=token_usage,
)
@@ -548,7 +548,7 @@ class SQLAppConversationInfoService(AppConversationInfoService):
return AppConversationInfo(
id=UUID(stored.conversation_id),
created_by_user_id=None, # User ID is now stored in ConversationMetadataSaas
- sandbox_id=stored.sandbox_id,
+ sandbox_id=sandbox_id, # Use the asserted non-None value
selected_repository=stored.selected_repository,
selected_branch=stored.selected_branch,
git_provider=(
@@ -556,7 +556,7 @@ class SQLAppConversationInfoService(AppConversationInfoService):
),
title=stored.title,
trigger=ConversationTrigger(stored.trigger) if stored.trigger else None,
- pr_number=stored.pr_number,
+ pr_number=stored.pr_number or [],
llm_model=stored.llm_model,
metrics=metrics,
parent_conversation_id=(