From cb1d1f8a0d437b47501580b48c8db4dbe84d3c27 Mon Sep 17 00:00:00 2001 From: Tim O'Farrell Date: Fri, 26 Dec 2025 10:53:21 -0700 Subject: [PATCH] Fix install-hooks CronJob failing when gitlab_webhook table doesn't exist (#12167) Co-authored-by: openhands --- enterprise/sync/install_gitlab_webhooks.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/enterprise/sync/install_gitlab_webhooks.py b/enterprise/sync/install_gitlab_webhooks.py index 883fff9cc9..5988879389 100644 --- a/enterprise/sync/install_gitlab_webhooks.py +++ b/enterprise/sync/install_gitlab_webhooks.py @@ -4,6 +4,8 @@ from uuid import uuid4 from integrations.types import GitLabResourceType from integrations.utils import GITLAB_WEBHOOK_URL +from sqlalchemy import text +from storage.database import session_maker from storage.gitlab_webhook import GitlabWebhook, WebhookStatus from 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 store webhook_store = await GitlabWebhookStore.get_instance()