-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Fix certificate generation without persistent grades #29792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ def read( | |
| course_structure=None, | ||
| course_key=None, | ||
| create_if_needed=True, | ||
| send_course_grade_signals=True, | ||
| ): | ||
| """ | ||
| Returns the CourseGrade for the given user in the course. | ||
|
|
@@ -51,7 +52,7 @@ def read( | |
| if assume_zero_if_absent(course_data.course_key): | ||
| return self._create_zero(user, course_data) | ||
| elif create_if_needed: | ||
| return self._update(user, course_data) | ||
| return self._update(user, course_data, send_course_grade_signals=send_course_grade_signals) | ||
| else: | ||
| return None | ||
|
|
||
|
|
@@ -160,13 +161,16 @@ def _read(user, course_data): | |
| ) | ||
|
|
||
| @staticmethod | ||
| def _update(user, course_data, force_update_subsections=False): | ||
| def _update(user, course_data, force_update_subsections=False, send_course_grade_signals=True): | ||
| """ | ||
| Computes, saves, and returns a CourseGrade object for the | ||
| given user and course. | ||
| Sends a COURSE_GRADE_CHANGED signal to listeners and | ||
| COURSE_GRADE_NOW_PASSED if learner has passed course or | ||
| COURSE_GRADE_NOW_FAILED if learner is now failing course | ||
| Computes, saves, and returns a CourseGrade object for the given user and course. | ||
|
|
||
| send_course_grade_signals defines if signals should be sent. Use it to avoid recursion issues in | ||
| cases when the signal listener trying to get grades but Persistent Grades are disabled. | ||
| If True - sends: | ||
| COURSE_GRADE_CHANGED signal to listeners and | ||
| COURSE_GRADE_NOW_PASSED if learner has passed course or | ||
| COURSE_GRADE_NOW_FAILED if learner is now failing course | ||
| """ | ||
| should_persist = should_persist_grades(course_data.course_key) | ||
| if should_persist and force_update_subsections: | ||
|
|
@@ -193,26 +197,27 @@ def _update(user, course_data, force_update_subsections=False): | |
| passed=course_grade.passed, | ||
| ) | ||
|
|
||
| COURSE_GRADE_CHANGED.send_robust( | ||
| sender=None, | ||
| user=user, | ||
| course_grade=course_grade, | ||
| course_key=course_data.course_key, | ||
| deadline=course_data.course.end, | ||
| ) | ||
| if course_grade.passed: | ||
| COURSE_GRADE_NOW_PASSED.send( | ||
| sender=CourseGradeFactory, | ||
| user=user, | ||
| course_id=course_data.course_key, | ||
| ) | ||
| else: | ||
| COURSE_GRADE_NOW_FAILED.send( | ||
| sender=CourseGradeFactory, | ||
| if send_course_grade_signals: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is the case, that every time that I'm thinking that if signals should not be sent when persistent grades is disabled, then we could make the if statement dependant on that variable and avoid creating a new control variable that needs to be accounted for and passed by the generation_handler.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should send signals 1 time regardless of the persistent grade status. The flow is:
here we should not break the signal sending
here we should avoid sending the signals
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense. we should not send the signal within the processing of the same signal. Since this was the last pending thing, I'll leave my approve |
||
| COURSE_GRADE_CHANGED.send_robust( | ||
| sender=None, | ||
| user=user, | ||
| course_id=course_data.course_key, | ||
| grade=course_grade, | ||
| course_grade=course_grade, | ||
| course_key=course_data.course_key, | ||
| deadline=course_data.course.end, | ||
| ) | ||
| if course_grade.passed: | ||
| COURSE_GRADE_NOW_PASSED.send( | ||
| sender=CourseGradeFactory, | ||
| user=user, | ||
| course_id=course_data.course_key, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is using NOTE: I haven't tested this, I'm just curious if you have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice question!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tried this and can say that:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And calling it will lead to sending the signal and checking the certificate status again
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for testing that out! |
||
| ) | ||
| else: | ||
| COURSE_GRADE_NOW_FAILED.send( | ||
| sender=CourseGradeFactory, | ||
| user=user, | ||
| course_id=course_data.course_key, | ||
| grade=course_grade, | ||
| ) | ||
|
|
||
| log.info( | ||
| 'Grades: Update, %s, User: %s, %s, persisted: %s', | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you help me list the cases where we want to send the signals? At least in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably any place where the
CourseGradeFactory().read()used (because it calls the_update()if there is no persistent grade present).Some examples of the signal receivers:
to the course grade;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the whole is to not send the course grade related signals when generating the certificate task right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's the main goal to break the recursive grade recalculation when the certificate is generated