From 67627ec9293dddc91838aef772e980ac41cc0d20 Mon Sep 17 00:00:00 2001 From: Anna Gavrilman Date: Fri, 22 Jan 2021 10:39:02 -0500 Subject: [PATCH] Import exam grades: ignore no score rows (#4759) * Import exam grades: ignore no score rows * little fix --- .../management/commands/import_edx_exam_grades.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/exams/management/commands/import_edx_exam_grades.py b/exams/management/commands/import_edx_exam_grades.py index a10a8658b8..dd45c0d08b 100644 --- a/exams/management/commands/import_edx_exam_grades.py +++ b/exams/management/commands/import_edx_exam_grades.py @@ -70,11 +70,22 @@ def handle(self, *args, **kwargs): # pylint: disable=unused-argument,too-many-l exam_authorization.exam_no_show = True exam_authorization.save() else: + try: + score = float(row['score']) + except ValueError: + self.stdout.write( + self.style.ERROR('Failed to create grade: empty score for user {} and exam run {}'.format( + user.username, + exam_run.id + )) + ) + continue + defaults = { 'passing_score': exam_run.passing_score, - 'score': float(row['score']), + 'score': score, 'grade': row['grade'], - 'percentage_grade': float(row['score']) / 100.0 if row['score'] else 0, + 'percentage_grade': score / 100.0 if score else 0, 'passed': row['grade'].lower() == EXAM_GRADE_PASS, 'row_data': row, 'exam_date': now_in_utc()