Moodle

There is nothing to prevent deletion of questions used by a random question

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.7.2, 1.8.1
  • Fix Version/s: 2.1
  • Component/s: Quiz
  • Labels:
    None
  • Environment:
    All
  • URL:
    /mod/quiz/review.php?q=75&attempt=4731
  • Affected Branches:
    MOODLE_17_STABLE, MOODLE_18_STABLE
  • Fixed Branches:
    MOODLE_21_STABLE

Description

Steps to reproduce:

1. Create a category X with some questions in.
2. Add a random question to a test quiz using this category.
3. Attempt this quiz as a student.
4. Delete the questions from this category.
5. Review the student's attempt.

Actual behaviour:

At step 5, you will see the error "This question has been deleted. Please contact your teacher" (which, incidentally, should have a full stop at the end.)

Expected behaviour:

At step 4, any questions that are in use should not be really deleted, but instead should merely have their deleted flag set.

Activity

Hide
Tim Hunt added a comment -

How do you get this message to appear? I can't make it happen. (Moodle does not let you delete questions that are used in a quiz, it just hides them instead.)

Show
Tim Hunt added a comment - How do you get this message to appear? I can't make it happen. (Moodle does not let you delete questions that are used in a quiz, it just hides them instead.)
Hide
Tim Hunt added a comment -

In the absence of further information, I am resolving this 'Cannot reproduce'.

If anyone can reproduce this, please reopen the bug with more infromation.

Show
Tim Hunt added a comment - In the absence of further information, I am resolving this 'Cannot reproduce'. If anyone can reproduce this, please reopen the bug with more infromation.
Hide
Brett Hinton added a comment -

This issue can be reproduced when creating a quiz that pulls random questions from a specific question category. When such a quiz is created Moodle doesn't seem to recognize that those questions "belong" to a specific quiz (since they technically don't until the moment a user takes the quiz). Since it doesn't recognize that these questions have been used, the questions can be deleted. When this occurs, the users who have already taken the quiz and received the question before it had been deleted will see the result that is reported above when they go into their quiz results.

It seems the issue is that the detection mechanism for random quizzes can be improved (easy for me to say but probably hard to do).

Let me know if you need additional info to reproduce the issue. This is showing up on the latest versions of 1.8

Show
Brett Hinton added a comment - This issue can be reproduced when creating a quiz that pulls random questions from a specific question category. When such a quiz is created Moodle doesn't seem to recognize that those questions "belong" to a specific quiz (since they technically don't until the moment a user takes the quiz). Since it doesn't recognize that these questions have been used, the questions can be deleted. When this occurs, the users who have already taken the quiz and received the question before it had been deleted will see the result that is reported above when they go into their quiz results. It seems the issue is that the detection mechanism for random quizzes can be improved (easy for me to say but probably hard to do). Let me know if you need additional info to reproduce the issue. This is showing up on the latest versions of 1.8
Hide
Brett Hinton added a comment -

See this Moodle discussion for an additional recent report of this issue:
http://moodle.org/mod/forum/discuss.php?d=74257

Show
Brett Hinton added a comment - See this Moodle discussion for an additional recent report of this issue: http://moodle.org/mod/forum/discuss.php?d=74257
Hide
Tim Hunt added a comment -

Suggested solution: in addition to whatever checks are currently done to see whether the question is in use, try to work out the correct query on the question_states table to see if the question is used by any random question. But actually, this is likely to be very expensive. It will need to be

SELECT COUNT(1) FROM mdl_question_states qst, mdl_question q WHERE qst.question = q.id AND q.qtype = 'random' AND q.answer LIKE '%random[questiontodeleteid]%'

If that returns greater than 0, then don't really delete the question.

Show
Tim Hunt added a comment - Suggested solution: in addition to whatever checks are currently done to see whether the question is in use, try to work out the correct query on the question_states table to see if the question is used by any random question. But actually, this is likely to be very expensive. It will need to be SELECT COUNT(1) FROM mdl_question_states qst, mdl_question q WHERE qst.question = q.id AND q.qtype = 'random' AND q.answer LIKE '%random[questiontodeleteid]%' If that returns greater than 0, then don't really delete the question.
Hide
Tim Hunt added a comment -

Fixing this involves building on the work done to fix MDL-11081. Fixing this bug basically means doing the "TODO: we should also consider other questions that are used by random questions in this quiz, but that is very hard."

Show
Tim Hunt added a comment - Fixing this involves building on the work done to fix MDL-11081. Fixing this bug basically means doing the "TODO: we should also consider other questions that are used by random questions in this quiz, but that is very hard."
Hide
Tim Hunt added a comment -

I think some SQL like

SELECT DISTINCT question FROM mdl_question_states WHERE SUBSTRING(answer FROM 7 FOR (POSITION(answer, '-') - 7)) = $questionid;

That is at least standard SQL that gives the correct answer, but performance will suck, because it will lead to table scans on the mdl_question_states table, which is huge.

Show
Tim Hunt added a comment - I think some SQL like SELECT DISTINCT question FROM mdl_question_states WHERE SUBSTRING(answer FROM 7 FOR (POSITION(answer, '-') - 7)) = $questionid; That is at least standard SQL that gives the correct answer, but performance will suck, because it will lead to table scans on the mdl_question_states table, which is huge.
Hide
Pierre Pichet added a comment -

Perhaps we should solve it by adding a quizz parameter to the question table that could be setted when the random (or random a match) question select this question on an attempt.

Show
Pierre Pichet added a comment - Perhaps we should solve it by adding a quizz parameter to the question table that could be setted when the random (or random a match) question select this question on an attempt.
Hide
Pierre Pichet added a comment -

As we need a flag so that a question sould not be deleted if it has been used in a quiz attempt, just adding a used_in_quizz parameter to the question table could be sufficient and will simplify all concurrent access that can occur if the quiz parameter is a list of quizzes like the questions parameter in quiz table.

Show
Pierre Pichet added a comment - As we need a flag so that a question sould not be deleted if it has been used in a quiz attempt, just adding a used_in_quizz parameter to the question table could be sufficient and will simplify all concurrent access that can occur if the quiz parameter is a list of quizzes like the questions parameter in quiz table.
Hide
Pierre Pichet added a comment -

Tim and Jamie,
What is the best way to handle questions deleting?
If we look at the problems related to the use of random or cloze questions or the new feature that allows students to create questions, it seems better to stop deleting questions...

Show
Pierre Pichet added a comment - Tim and Jamie, What is the best way to handle questions deleting? If we look at the problems related to the use of random or cloze questions or the new feature that allows students to create questions, it seems better to stop deleting questions...
Hide
Tim Hunt added a comment -

That proposal does not work, because quiz attempts can be deleted. When that happens, you don't know whether to unset the used_in_quiz flag, because you don't know if this question is used in other attempts or not.

I am becoming increasingly convinced that the long-term solution to this problem is to change how random questions work - to remove the random question type, and instead make the quiz responsible for doing the randomisation.

In the short to medium term, there may be a solution involving adding a column to mdl_question_sessions.

Show
Tim Hunt added a comment - That proposal does not work, because quiz attempts can be deleted. When that happens, you don't know whether to unset the used_in_quiz flag, because you don't know if this question is used in other attempts or not. I am becoming increasingly convinced that the long-term solution to this problem is to change how random questions work - to remove the random question type, and instead make the quiz responsible for doing the randomisation. In the short to medium term, there may be a solution involving adding a column to mdl_question_sessions.
Hide
Pierre Pichet added a comment -

Your solution of adding a column to mdl_question_sessions should also work with the random as match question type as this imply more than one question being used as subquestion.
In the mean time, should we put a warning in the delete question process so that the user has to be sure that these questions where not used in a quiz directly or as random or as random as match questions?

Show
Pierre Pichet added a comment - Your solution of adding a column to mdl_question_sessions should also work with the random as match question type as this imply more than one question being used as subquestion. In the mean time, should we put a warning in the delete question process so that the user has to be sure that these questions where not used in a quiz directly or as random or as random as match questions?
Hide
Wen Hao Chuang added a comment -

I believe this is still an issue in 1.9.x now, any update on this one? Thanks!

Show
Wen Hao Chuang added a comment - I believe this is still an issue in 1.9.x now, any update on this one? Thanks!
Hide
Tim Hunt added a comment -

Yes it is still an issue. I am still convinced that it some point we need to completely change how random questions work, so we can fix problems like this, and the difficulty of doing random essay questions. However, I don't think I will have time for that any time soon.

Show
Tim Hunt added a comment - Yes it is still an issue. I am still convinced that it some point we need to completely change how random questions work, so we can fix problems like this, and the difficulty of doing random essay questions. However, I don't think I will have time for that any time soon.
Hide
Michael de Raadt added a comment -

Thanks for reporting this issue.

We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

Michael d;

lqjjLKA0p6

Show
Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d; lqjjLKA0p6
Hide
Michael de Raadt added a comment -

I'm closing this issue as it has become inactive and does not appear to affect a current supported version. If you are encountering this problem or one similar, please launch a new issue.

Show
Michael de Raadt added a comment - I'm closing this issue as it has become inactive and does not appear to affect a current supported version. If you are encountering this problem or one similar, please launch a new issue.
Hide
Tim Hunt added a comment -

Just reopening to give a better resolution.

Show
Tim Hunt added a comment - Just reopening to give a better resolution.
Hide
Tim Hunt added a comment -

This was actually fixed in Moodle 2.1, as part of MDL-20636, the new question engine.

Show
Tim Hunt added a comment - This was actually fixed in Moodle 2.1, as part of MDL-20636, the new question engine.

People

Vote (2)
Watch (7)

Dates

  • Created:
    Updated:
    Resolved: