From 39ebf71ae876ebbe4de9e5e767749bf6ffe9883c Mon Sep 17 00:00:00 2001 From: Vikrant Date: Fri, 18 Sep 2026 01:05:46 +0530 Subject: [PATCH] Do not persist REPORTED status when the main-table transfer fails update_student_status saved reported_status = REPORTED before attempting the ExtraInfo/Student/User transfer, so a failed transfer (batch not found, or any exception during the transfer) left the status permanently stuck at REPORTED with nothing actually created. That also disabled retries, since the guard that triggers the transfer only fires when old_status != REPORTED. Revert the status back to old_status on every failure path in that block, and report success:false with an honest message when the transfer didn't complete. This covers UG, PG and PhD alike since they share this same function. --- .../api/views_student_management.py | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/FusionIIIT/applications/programme_curriculum/api/views_student_management.py b/FusionIIIT/applications/programme_curriculum/api/views_student_management.py index 04ea389d0..f1bbfa314 100644 --- a/FusionIIIT/applications/programme_curriculum/api/views_student_management.py +++ b/FusionIIIT/applications/programme_curriculum/api/views_student_management.py @@ -2134,6 +2134,8 @@ def update_student_status(request): ).first() if not batch_obj: + student.reported_status = old_status + student.save() return JsonResponse({ 'success': False, 'message': f'No batch found for {batch_name} {discipline.name} Year-{student.year}. Please create the required batch first.', @@ -2194,6 +2196,8 @@ def update_student_status(request): discipline = batch_obj.discipline if not batch_obj: + student.reported_status = old_status + student.save() return JsonResponse({ 'success': False, 'message': f'No batch found for {programme_name} {discipline.name} Year-{student.year} with specialization {student.specialization}. Please create the required batch manually first.', @@ -2433,6 +2437,8 @@ def update_student_status(request): transfer_message = "Transfer skipped: No roll number assigned" except Exception as e: + student.reported_status = old_status + student.save() transfer_message = f"Status updated but transfer failed: {str(e)}" elif reported_status in ['NOT_REPORTED', 'PENDING', 'WITHDRAWAL'] and old_status == 'REPORTED': @@ -2530,21 +2536,28 @@ def update_student_status(request): pass # Prepare descriptive response message - if reported_status == 'REPORTED' and old_status != 'REPORTED': + transfer_failed = ( + reported_status == 'REPORTED' + and old_status != 'REPORTED' + and not transfer_success + ) + if transfer_failed: + main_message = f'Failed to report student, nothing was changed: {transfer_message}' + elif reported_status == 'REPORTED' and old_status != 'REPORTED': main_message = f'Student status updated to {reported_status} and transferred to main academic system' elif reported_status in ['NOT_REPORTED', 'PENDING', 'WITHDRAWAL'] and old_status == 'REPORTED': main_message = f'Student status reverted to {reported_status} and removed from main academic system' else: main_message = f'Student status updated to {reported_status}' - + response_data = { - 'success': True, + 'success': not transfer_failed, 'message': main_message, 'data': { 'student_id': student.id, 'roll_number': student.roll_number, 'old_status': old_status, - 'new_status': reported_status, + 'new_status': student.reported_status, 'transfer_success': transfer_success, 'transfer_message': transfer_message, 'user_created': user_created,