From 551e31b84d9f0f2561d2a062df2c7b264a75e527 Mon Sep 17 00:00:00 2001 From: openhands Date: Mon, 20 Oct 2025 13:12:17 +0000 Subject: [PATCH] Add error handling for missing gitlab_webhook table Adds defensive error handling in install_gitlab_webhooks.py to catch table not found errors and provide clear, actionable error messages. Root Cause: - Migration 027 created table as 'gitlab-webhook' (with hyphen) - SQLAlchemy model expects 'gitlab_webhook' (with underscore) - Migration 032 fixes this but may not be applied in all environments This change: - Catches UndefinedTableError when querying gitlab_webhook table - Logs clear error message indicating migration 032 is needed - Returns gracefully to prevent continuous error logging - Provides actionable guidance: 'alembic upgrade head' Impact: - Prevents cronjob from crashing repeatedly in Datadog - Makes it immediately clear to operators what action is needed - Reduces noise in error logs Fixes error seen in Datadog logs since Oct 13, 2025: relation "gitlab_webhook" does not exist Co-authored-by: openhands --- enterprise/sync/install_gitlab_webhooks.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/enterprise/sync/install_gitlab_webhooks.py b/enterprise/sync/install_gitlab_webhooks.py index 883fff9cc9..1d90e6405f 100644 --- a/enterprise/sync/install_gitlab_webhooks.py +++ b/enterprise/sync/install_gitlab_webhooks.py @@ -262,7 +262,24 @@ class VerifyWebhookStatus: webhook_store = await GitlabWebhookStore.get_instance() # Load chunks of rows that need processing (webhook_exists == False) - webhooks_to_process = await self.fetch_rows(webhook_store) + try: + webhooks_to_process = await self.fetch_rows(webhook_store) + except Exception as e: + # Check if this is a table not found error (likely due to missing migration) + if 'does not exist' in str(e) and ('gitlab_webhook' in str(e) or 'gitlab-webhook' in str(e)): + logger.error( + 'gitlab_webhook table does not exist. This usually means database migration 032 ' + 'or later has not been applied. Please run database migrations: alembic upgrade head', + extra={ + 'error_type': type(e).__name__, + 'error_message': str(e), + 'migration_needed': '032_add_status_column_to_gitlab_webhook.py', + }, + ) + # Return early to avoid continuous error logging + return + # Re-raise other exceptions + raise logger.info( 'Processing webhook chunks',