Hi

A very high number of points (>4000) are being added to a users score due to a quiz being created with an overall max score that appears to be the total of all existing quiz max scores.

Be great if you can help on this as we have quiz working in production and currently it is preventing any new quizzes from being added to the site.

I've tracked down the error to the quiz.module (see below)

1. $questions = entity_load('quiz_question_relationship') loads all the existing questions

2. when iterating through all the questions - the following line is always true - "if ($question->question_status)" and so $max_score ends up being the sum of all the questions max scores and not just those associated with each quiz.

3. It feels like an update script has failed but I had no reports of this when i performed the latest update.

function quiz_update_max_score_properties(array $quizzes) {
foreach ($quizzes as $vid) {
$max_score = 0;
$questions = entity_load('quiz_question_relationship');
$quiz_entities = entity_load('quiz', FALSE, array('vid' => $vid));
if ($quiz = reset($quiz_entities)) {
if ($quiz->randomization == 3) {
// Count taxonomy questions.
foreach (_quiz_get_terms($quiz->vid) as $term) {
$max_score += $term->max_score * $term->number;
}
}
else {
foreach ($questions as $question) {
if ($question->question_status) {
// Count required questions.
$max_score += $question->max_score;
}
}

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Tim Corkerton created an issue. See original summary.

djdevin’s picture

Yes, it does look like something is wrong here. I am very surprised this hasn't come up before. First of all there should not be an entity_load('quiz_question_relationship'); which would be loading all question relationships on the site.

The strange thing is we have tests for this so I'm wondering what use case we missed here.

I do see that there is a foreach() around the quizzes passed to this function - is your use case possibly having Quizzes pulling from a pool of random questions that are also shared to other Quizzes on the site?

Tim Corkerton’s picture

Our use case is fairly simple. We have hundreds of multiple choice questions and we rarely use them in more than one quiz. The max points variable is set to the max number of points of all questions even if we do the following.

1. Create a new quiz
2. Add a multiple choice question - Leave all as defaults and add 2 answers, i check that one is marked as correct (1 point) and one is marked as incorrect (0 points)
3. Submit the form.
4. Take the quiz and over 4000 points are awarded

However, if we check the update max points boxes for the question/s then save the quiz, it appears to recalculate the max_points for the quiz. However we can't rely on this since if someone forgets then the whole scoreboard is corrupted.

I have also tried adding in some other question types and they appear to have a similar issue so i don't think it's particular to the multiple choice question

djdevin’s picture

Version: 7.x-5.1 » 7.x-5.x-dev
Ron Collins’s picture

I'm experiencing the same issue on 5.4.

First, thanks to @tim-corkerton for the workaround. The reason it works if you select AUTO UPDATE MAX SCORE and save the questions is because after the module runs through quiz_update_max_score_properties() which sets the incorrect value for max_score in the quiz_node_properties table (ours are also in the 4000 range but that's probably a coincidence based on the number of questions in the db), it then eventually hits quiz_questions_form_submit() which resets the value to the correct number.

The problem happens whether I create a new quiz or simply update an existing quiz by going to the edit page and hitting save (no other changes). This is an upgrade from quiz 4. I've made a lot of customizations but this seems to be problem with quiz_update_max_score_properties(). We do also use questions in multiple quizzes.

I'm wondering why quiz_update_max_score_properties() is loading all questions from all quizzes? That's got to be inefficient and I'm guessing unnecessary? Perhaps it just needs to get changed to the way that quiz_questions_form_submit() works?

@djdevin if you want I can take a shot at patching that if you think it's the right approach.

The other thing I am noticing is that the aid field in the quiz_node_properties table is set to null after saving the quiz. Is that field not being used any more? It should probably be removed if that's the case. Probably not related to this issue?

Ron Collins’s picture

I've also discovered that turning off auto revisioning in the quiz setting stops this problem. Not recommended by the module maintainers but it might work for us.

djdevin’s picture

Status: Active » Needs review
FileSize
0 bytes

This problem does appear to fix itself, only the action of adding a new question messes up the point total. Resubmitting the "Manage questions" form or doing something that recalculates max_score also fixes the problem.

This is because in quiz_questions_form_submit() there is another max score calculation happening.

Ideally this would be combined in some logical sense but for now this is a simple change to fix the issue.

djdevin’s picture

FileSize
609 bytes
djdevin’s picture

Status: Needs review » Fixed

  • djdevin committed 775d8e9 on 7.x-5.x
    Issue #2884798 by djdevin: max_score is incorrect whenever a new quiz is...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.