diff --git a/app/stiftung/views.py b/app/stiftung/views.py index 898860a..8a369b7 100644 --- a/app/stiftung/views.py +++ b/app/stiftung/views.py @@ -6019,7 +6019,9 @@ def backup_cancel(request, backup_id): print(f"DEBUG: Attempting to cancel backup job {backup_id}") backup_job = BackupJob.objects.get(id=backup_id) print(f"DEBUG: Found backup job - ID: {backup_job.id}, Status: {backup_job.status}") - print(f"DEBUG: Created by: {backup_job.created_by}, Current user: {request.user}") + + # Use created_by_id instead of created_by to avoid triggering the foreign key lookup + print(f"DEBUG: Created by ID: {backup_job.created_by_id}, Current user ID: {request.user.id}") # Only allow cancelling running or pending jobs if backup_job.status not in ['running', 'pending']: @@ -6027,9 +6029,9 @@ def backup_cancel(request, backup_id): return redirect("stiftung:backup_management") # Check if user has permission to cancel (either own job or admin) - # Handle case where created_by might be None (user deleted) - print(f"DEBUG: Checking permissions - created_by: {backup_job.created_by}, is_staff: {request.user.is_staff}") - if backup_job.created_by is not None and backup_job.created_by != request.user and not request.user.is_staff: + # Use created_by_id to avoid database lookup for potentially non-existent user + print(f"DEBUG: Checking permissions - created_by_id: {backup_job.created_by_id}, is_staff: {request.user.is_staff}") + if backup_job.created_by_id is not None and backup_job.created_by_id != request.user.id and not request.user.is_staff: messages.error(request, "Sie können nur Ihre eigenen Backup-Jobs abbrechen.") return redirect("stiftung:backup_management")