From 36a42bf4c064a43d8635d57f27ad2dbc77d1b96b Mon Sep 17 00:00:00 2001 From: annagav Date: Tue, 19 Jan 2021 18:33:46 -0500 Subject: [PATCH] Import exam grades: ignore no score rows --- .../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..4dd843d108 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 row['score'] else 0, 'passed': row['grade'].lower() == EXAM_GRADE_PASS, 'row_data': row, 'exam_date': now_in_utc()