def _recalculate_subsection_grade(task_func, **kwargs):
 try:
  course_key = CourseLocator.from_string(kwargs['course_id'])
  if (not PersistentGradesEnabledFlag.feature_enabled(course_key)):
   return
  scored_block_usage_key = UsageKey.from_string(kwargs['usage_id']).replace(course_key=course_key)
  set_event_transaction_id(kwargs.get('event_transaction_id'))
  set_event_transaction_type(kwargs.get('event_transaction_type'))
  if (task_func == recalculate_subsection_grade_v2):
   has_database_updated = _has_db_updated_with_new_score_bwc_v2(kwargs['user_id'], scored_block_usage_key, from_timestamp(kwargs['expected_modified_time']), kwargs['score_deleted'])
  else:
   has_database_updated = _has_db_updated_with_new_score(scored_block_usage_key, **kwargs)
  if (not has_database_updated):
   raise _retry_recalculate_subsection_grade(task_func, **kwargs)
  _update_subsection_grades(course_key, scored_block_usage_key, kwargs['only_if_higher'], kwargs['user_id'])
 except Exception as exc:
  if (not isinstance(exc, KNOWN_RETRY_ERRORS)):
   log.info('tnl-6244 grades unexpected failure: {}. kwargs={}'.format(repr(exc), kwargs))
  raise _retry_recalculate_subsection_grade(task_func, exc=exc, **kwargs)

def _recalculate_subsection_grade ( task_func , ** kwargs ) : try : course_key = CourseLocator . from_string ( kwargs [ 'course_id' ] ) if ( not PersistentGradesEnabledFlag . feature_enabled ( course_key ) ) : return scored_block_usage_key = UsageKey . from_string ( kwargs [ 'usage_id' ] ) . replace ( course_key = course_key ) set_event_transaction_id ( kwargs . get ( 'event_transaction_id' ) ) set_event_transaction_type ( kwargs . get ( 'event_transaction_type' ) ) if ( task_func == recalculate_subsection_grade_v2 ) : has_database_updated = _has_db_updated_with_new_score_bwc_v2 ( kwargs [ 'user_id' ] , scored_block_usage_key , from_timestamp ( kwargs [ 'expected_modified_time' ] ) , kwargs [ 'score_deleted' ] ) else : has_database_updated = _has_db_updated_with_new_score ( scored_block_usage_key , ** kwargs ) if ( not has_database_updated ) : raise _retry_recalculate_subsection_grade ( task_func , ** kwargs ) _update_subsection_grades ( course_key , scored_block_usage_key , kwargs [ 'only_if_higher' ] , kwargs [ 'user_id' ] ) except Exception as exc : if ( not isinstance ( exc , KNOWN_RETRY_ERRORS ) ) : log . info ( 'tnl-6244 grades unexpected failure: {}. kwargs={}' . format ( repr ( exc ) , kwargs ) ) raise _retry_recalculate_subsection_grade ( task_func , exc = exc , ** kwargs )
updates a saved subsection grade .