From 715076a48b60cc2c1a64070b2d0cc8da79d65048 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 27 Feb 2017 13:04:25 -0500 Subject: [PATCH] Cleaner grades exception handling --- lms/djangoapps/grades/tasks.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/grades/tasks.py b/lms/djangoapps/grades/tasks.py index b6325af654..0359deed1d 100644 --- a/lms/djangoapps/grades/tasks.py +++ b/lms/djangoapps/grades/tasks.py @@ -33,7 +33,20 @@ from .transformer import GradesTransformer log = getLogger(__name__) -KNOWN_RETRY_ERRORS = (DatabaseError, ValidationError) # Errors we expect occasionally, should be resolved on retry + +class DatabaseNotReadyError(IOError): + """ + Subclass of IOError to indicate the database has not yet committed + the data we're trying to find. + """ + pass + + +KNOWN_RETRY_ERRORS = ( # Errors we expect occasionally, should be resolved on retry + DatabaseError, + ValidationError, + DatabaseNotReadyError +) RECALCULATE_GRADE_DELAY = 2 # in seconds, to prevent excessive _has_db_updated failures. See TNL-6424. @@ -101,7 +114,7 @@ def _recalculate_subsection_grade(self, **kwargs): has_database_updated = _has_db_updated_with_new_score(self, scored_block_usage_key, **kwargs) if not has_database_updated: - raise _retry_recalculate_subsection_grade(self, **kwargs) + raise DatabaseNotReadyError _update_subsection_grades( course_key, @@ -109,8 +122,6 @@ def _recalculate_subsection_grade(self, **kwargs): kwargs['only_if_higher'], kwargs['user_id'], ) - except Retry: - raise except Exception as exc: # pylint: disable=broad-except if not isinstance(exc, KNOWN_RETRY_ERRORS): log.info("tnl-6244 grades unexpected failure: {}. task id: {}. kwargs={}".format(