@@ -59,30 +59,34 @@ def _post_async_submission(request, exercise, submission, errors=None):
5959 submission .grading_data = post_data
6060
6161 if 'grading_data' in submission .grading_data :
62- grader_grading_data = json .loads (submission .grading_data ['grading_data' ])
63- if 'submission_tags' in grader_grading_data :
64- for tag_slug in grader_grading_data ['submission_tags' ].split (',' ):
65- tag_slug = tag_slug .strip ()
66- if tag_slug :
67- try :
68- # Try to get the tag and validate it belongs to the course
69- tag = SubmissionTag .objects .get (
70- slug = tag_slug ,
71- course_instance = submission .exercise .course_module .course_instance ,
72- )
73- # Only attempt to create SubmissionTagging if it does not exist already
74- if not SubmissionTagging .objects .filter (submission = submission , tag = tag ).exists ():
75- SubmissionTagging .objects .create (submission = submission , tag = tag )
76- except SubmissionTag .DoesNotExist :
77- # Send an email to course instance's technical support emails and teachers
78- # if the submission tags are misconfigured
79- if exercise .course_instance .visible_to_students :
80- msg = (
81- f"Failed to tag submission: Submission tag '{ tag_slug } ' not found "
82- "or not part of this course instance."
62+ try :
63+ grader_grading_data = json .loads (submission .grading_data ['grading_data' ])
64+ if 'submission_tags' in grader_grading_data :
65+ for tag_slug in grader_grading_data ['submission_tags' ].split (',' ):
66+ tag_slug = tag_slug .strip ()
67+ if tag_slug :
68+ try :
69+ # Try to get the tag and validate it belongs to the course
70+ tag = SubmissionTag .objects .get (
71+ slug = tag_slug ,
72+ course_instance = submission .exercise .course_module .course_instance ,
8373 )
84- logger .error (msg , extra = {"request" : request })
85- email_course_error (request , exercise , msg , True )
74+ # Only attempt to create SubmissionTagging if it does not exist already
75+ if not SubmissionTagging .objects .filter (submission = submission , tag = tag ).exists ():
76+ SubmissionTagging .objects .create (submission = submission , tag = tag )
77+ except SubmissionTag .DoesNotExist :
78+ # Send an email to course instance's technical support emails and teachers
79+ # if the submission tags are misconfigured
80+ if exercise .course_instance .visible_to_students :
81+ msg = (
82+ f"Failed to tag submission: Submission tag '{ tag_slug } ' not found "
83+ "or not part of this course instance."
84+ )
85+ logger .error (msg , extra = {"request" : request })
86+ email_course_error (request , exercise , msg , True )
87+ except json .JSONDecodeError :
88+ # If the grading data is not valid JSON, we cannot extract submission tags
89+ pass
8690
8791 # If A+ is used as LTI Tool and the assignment uses the Acos-server,
8892 # the submission has not been able to save the LTI launch id before
0 commit comments