From ed11b9c6341634585f4a527fbeb048a7af8769d8 Mon Sep 17 00:00:00 2001 From: poduck Date: Fri, 28 Nov 2025 05:33:56 -0500 Subject: [PATCH] fix: Prevent notification errors from rolling back ticket creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add availability check for notifications app to avoid database errors when the notifications table doesn't exist. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- smoothschedule/tickets/signals.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/smoothschedule/tickets/signals.py b/smoothschedule/tickets/signals.py index 544b05f..4f85271 100644 --- a/smoothschedule/tickets/signals.py +++ b/smoothschedule/tickets/signals.py @@ -1,4 +1,5 @@ import logging +from django.db import transaction from django.db.models.signals import post_save from django.dispatch import receiver from django.utils import timezone @@ -11,6 +12,24 @@ from smoothschedule.users.models import User logger = logging.getLogger(__name__) +# Flag to check if notifications app is available +_notifications_available = None + + +def is_notifications_available(): + """Check if the notifications app is installed and migrated.""" + global _notifications_available + if _notifications_available is None: + try: + from notifications.models import Notification + # Check if the table exists by doing a simple query + Notification.objects.exists() + _notifications_available = True + except Exception: + _notifications_available = False + return _notifications_available + + def send_websocket_notification(group_name, message_data): """Safely send a WebSocket notification, handling errors gracefully.""" try: @@ -31,6 +50,11 @@ def send_websocket_notification(group_name, message_data): def create_notification(recipient, actor, verb, action_object, target, data): """Safely create a notification, handling import and creation errors.""" + # Skip notification creation if the notifications app is not available + if not is_notifications_available(): + logger.debug("notifications app not available, skipping notification creation") + return + try: from notifications.models import Notification Notification.objects.create(