Compare commits

...

1 Commits

Author SHA1 Message Date
openhands
1bad8f1ebc Fix: Handle missing openhands_prs table in OpenhandsPRStore
When the enrich_user_interaction_data cronjob runs, it queries the
openhands_prs table. If the database migrations haven't been run yet,
this causes a ProgrammingError because the table doesn't exist.

This fix wraps the database query in get_unprocessed_prs() with a
try-except block to catch the ProgrammingError and log a warning
instead of crashing. This allows the cronjob to complete gracefully
even if the database isn't fully initialized.

Co-authored-by: openhands <openhands@all-hands.dev>
2026-01-06 00:32:39 +00:00

View File

@@ -2,6 +2,7 @@ from dataclasses import dataclass
from datetime import datetime
from sqlalchemy import and_, desc
from sqlalchemy.exc import ProgrammingError
from sqlalchemy.orm import sessionmaker
from storage.database import session_maker
from storage.openhands_pr import OpenhandsPR
@@ -135,22 +136,29 @@ class OpenhandsPRStore:
Returns:
List of OpenhandsPR objects that need processing
"""
with self.session_maker() as session:
unprocessed_prs = (
session.query(OpenhandsPR)
.filter(
and_(
~OpenhandsPR.processed,
OpenhandsPR.process_attempts < max_retries,
OpenhandsPR.provider == ProviderType.GITHUB.value,
try:
with self.session_maker() as session:
unprocessed_prs = (
session.query(OpenhandsPR)
.filter(
and_(
~OpenhandsPR.processed,
OpenhandsPR.process_attempts < max_retries,
OpenhandsPR.provider == ProviderType.GITHUB.value,
)
)
.order_by(desc(OpenhandsPR.updated_at))
.limit(limit)
.all()
)
.order_by(desc(OpenhandsPR.updated_at))
.limit(limit)
.all()
)
return unprocessed_prs
return unprocessed_prs
except ProgrammingError as e:
logger.warning(
f'Could not query openhands_prs table - it may not exist yet. '
f'Run database migrations first. Error: {e}'
)
return []
@classmethod
def get_instance(cls):