def _has_db_updated_with_new_score(self, scored_block_usage_key, **kwargs): """ Returns whether the database has been updated with the expected new score values for the given problem and user. """ if kwargs[ 'score_db_table'] == ScoreDatabaseTableEnum.courseware_student_module: score = get_score(kwargs['user_id'], scored_block_usage_key) found_modified_time = score.modified if score is not None else None elif kwargs['score_db_table'] == ScoreDatabaseTableEnum.submissions: score = sub_api.get_score({ "student_id": kwargs['anonymous_user_id'], "course_id": six.text_type(scored_block_usage_key.course_key), "item_id": six.text_type(scored_block_usage_key), "item_type": scored_block_usage_key.block_type, }) found_modified_time = score['created_at'] if score is not None else None else: assert kwargs['score_db_table'] == ScoreDatabaseTableEnum.overrides from . import api score = api.get_subsection_grade_override( user_id=kwargs['user_id'], course_key_or_id=kwargs['course_id'], usage_key_or_id=kwargs['usage_id']) found_modified_time = score.modified if score is not None else None if score is None: # score should be None only if it was deleted. # Otherwise, it hasn't yet been saved. db_is_updated = kwargs['score_deleted'] else: db_is_updated = found_modified_time >= from_timestamp( kwargs['expected_modified_time']) if not db_is_updated: log.info( u"Grades: tasks._has_database_updated_with_new_score is False. Task ID: {}. Kwargs: {}. Found " u"modified time: {}".format( self.request.id, kwargs, found_modified_time, )) return db_is_updated
def validate_timestamp(self, value): """ Ensure the request has been received in a timely manner. """ date_time = from_timestamp(value) # Ensure we converted the timestamp to a datetime if not date_time: msg = f'[{value}] is not a valid timestamp' log.warning(msg) raise serializers.ValidationError(msg) elapsed = (datetime.datetime.now(pytz.UTC) - date_time).total_seconds() if elapsed > settings.CREDIT_PROVIDER_TIMESTAMP_EXPIRATION: msg = f'[{value}] is too far in the past (over [{elapsed}] seconds).' log.warning(msg) raise serializers.ValidationError(msg) return value