From 4e0b3d3b2e5913d0ebc45dd9b47f61ff08695845 Mon Sep 17 00:00:00 2001 From: "Albert St. Aubin" Date: Wed, 9 May 2018 08:24:24 -0400 Subject: [PATCH] Correctly passing course key in the JSON object to async [LEARNER-5123] --- lms/djangoapps/grades/signals/handlers.py | 13 +++++++------ lms/djangoapps/grades/tasks.py | 8 +++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lms/djangoapps/grades/signals/handlers.py b/lms/djangoapps/grades/signals/handlers.py index e5fd6ec90d..b7bd359870 100644 --- a/lms/djangoapps/grades/signals/handlers.py +++ b/lms/djangoapps/grades/signals/handlers.py @@ -4,17 +4,18 @@ Grades related signals. from contextlib import contextmanager from logging import getLogger +import six from courseware.model_data import get_score, set_score from django.dispatch import receiver +from submissions.models import score_reset, score_set +from xblock.scorable import ScorableXBlockMixin, Score + from openedx.core.djangoapps.course_groups.signals.signals import COHORT_MEMBERSHIP_UPDATED from openedx.core.lib.grade_utils import is_score_higher_or_equal from student.models import user_by_anonymous_id from student.signals import ENROLLMENT_TRACK_UPDATED -from submissions.models import score_reset, score_set from track.event_transaction_utils import get_event_transaction_id, get_event_transaction_type from util.date_utils import to_timestamp -from xblock.scorable import ScorableXBlockMixin, Score - from .signals import ( PROBLEM_RAW_SCORE_CHANGED, PROBLEM_WEIGHTED_SCORE_CHANGED, @@ -22,9 +23,9 @@ from .signals import ( SUBSECTION_SCORE_CHANGED, SUBSECTION_OVERRIDE_CHANGED, ) +from .. import events from ..constants import ScoreDatabaseTableEnum from ..course_grade_factory import CourseGradeFactory -from .. import events from ..scores import weighted_score from ..tasks import ( RECALCULATE_GRADE_DELAY_SECONDS, @@ -247,7 +248,7 @@ def recalculate_course_and_subsection_grades(sender, user, course_key, **kwargs) """ recalculate_course_and_subsection_grades_for_user.apply_async( kwargs=dict( - user=user, - course_key=course_key + user_id=user.id, + course_key=six.text_type(course_key) ) ) diff --git a/lms/djangoapps/grades/tasks.py b/lms/djangoapps/grades/tasks.py index b2dcaed31d..fee3f75d10 100644 --- a/lms/djangoapps/grades/tasks.py +++ b/lms/djangoapps/grades/tasks.py @@ -127,13 +127,15 @@ def recalculate_course_and_subsection_grades_for_user(self, **kwargs): # pylint Recalculates the course grade and all subsection grades for the given ``user`` and ``course_key`` keyword arguments. """ - user = kwargs.get('user') - course_key = kwargs.get('course_key') + user_id = kwargs.get('user_id') + course_key_str = kwargs.get('course_key') - if not user or course_key: + if not user_id or course_key_str: message = 'recalculate_course_and_subsection_grades_for_user missing "user" or "course_key" kwargs from {}' log.error(message.format(kwargs)) + user = User.objects.get(id=user_id) + course_key = CourseKey.from_string(course_key_str) previous_course_grade = CourseGradeFactory().read(user, course_key=course_key) if previous_course_grade and previous_course_grade.attempted: CourseGradeFactory().update(