diff --git a/app/stiftung/views.py b/app/stiftung/views.py index f0ebd3c..6b13d88 100644 --- a/app/stiftung/views.py +++ b/app/stiftung/views.py @@ -6023,7 +6023,8 @@ def backup_cancel(request, backup_id): return redirect("stiftung:backup_management") # Check if user has permission to cancel (either own job or admin) - if backup_job.created_by != request.user and not request.user.is_staff: + # Handle case where created_by might be None (user deleted) + if backup_job.created_by is not None and backup_job.created_by != request.user and not request.user.is_staff: messages.error(request, "Sie können nur Ihre eigenen Backup-Jobs abbrechen.") return redirect("stiftung:backup_management") @@ -6034,14 +6035,18 @@ def backup_cancel(request, backup_id): backup_job.error_message = f"Abgebrochen von {request.user.username}" backup_job.save() - # Log the cancellation - from stiftung.audit import log_system_action - log_system_action( - request=request, - action="backup_cancel", - description=f"Backup-Job abgebrochen: {backup_job.get_backup_type_display()}", - details={"backup_job_id": str(backup_job.id)}, - ) + # Log the cancellation (with error handling) + try: + from stiftung.audit import log_system_action + log_system_action( + request=request, + action="backup_cancel", + description=f"Backup-Job abgebrochen: {backup_job.get_backup_type_display()}", + details={"backup_job_id": str(backup_job.id)}, + ) + except Exception as audit_error: + # Don't fail the cancellation if logging fails + print(f"Warning: Could not log backup cancellation: {audit_error}") messages.success(request, f"Backup-Job wurde abgebrochen.")