fix: Prevent notification errors from rolling back ticket creation
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user