Skip to content

Commit

Permalink
Catch and pass exceptions related to unique key contraints
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebrownlee committed Feb 26, 2024
1 parent 291548f commit fd488e9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions LearningAPI/views/student_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import requests
from django.db import connection
from django.db import IntegrityError
from django.http import HttpResponseServerError
from django.utils.decorators import method_decorator
from rest_framework import serializers, status
Expand Down Expand Up @@ -215,11 +216,14 @@ def assess(self, request, pk):
# 2. Assign all objectives/weights to the student as complete
assessment_objectives = latest_assessment.assessment.objectives.all()
for objective in assessment_objectives:
LearningRecord.objects.create(
student=student,
weight=objective,
achieved=True,
)
try:
LearningRecord.objects.create(
student=student,
weight=objective,
achieved=True,
)
except IntegrityError:
pass

except Exception:
return Response({'message': 'Updated, but no Slack message sent'}, status=status.HTTP_204_NO_CONTENT)
Expand Down

0 comments on commit fd488e9

Please sign in to comment.