π OpenHands: AI-Driven Development
Fix install-hooks CronJob failing when gitlab_webhook table doesn't exist (#12167)
Tim O'Farrellcb1d1f8a0d43
diff --git a/enterprise/sync/install_gitlab_webhooks.py b/enterprise/sync/install_gitlab_webhooks.pyindex 883fff9cc9..5988879389 100644--- a/enterprise/sync/install_gitlab_webhooks.py+++ b/enterprise/sync/install_gitlab_webhooks.py@@ -4,6 +4,8 @@ from uuid import uuid4from integrations.types import GitLabResourceTypefrom integrations.utils import GITLAB_WEBHOOK_URL+from sqlalchemy import text+from storage.database import session_makerfrom storage.gitlab_webhook import GitlabWebhook, WebhookStatusfrom storage.gitlab_webhook_store import GitlabWebhookStore@@ -258,6 +260,25 @@ class VerifyWebhookStatus:from integrations.gitlab.gitlab_service import SaaSGitLabService+ # Check if the table exists before proceeding+ # This handles cases where the CronJob runs before database migrations complete+ with session_maker() as session:+ query = text("""+ SELECT EXISTS (+ SELECT FROM information_schema.tables+ WHERE table_name = 'gitlab_webhook'+ )+ """)+ result = await session.execute(query)+ table_exists = result.scalar() or False++ if not table_exists:+ logger.info(+ 'gitlab_webhook table does not exist yet, '+ 'waiting for database migrations to complete'+ )+ return+# Get an instance of the webhook storewebhook_store = await GitlabWebhookStore.get_instance()