Fatal Error: Class name must be a valid object or a string in ../quiz/question_types/quiz_question/quiz_question.module on line 646

Hi

I'm getting this error when trying to view previously passed quizzes as in node/%/quiz-results/%/view

The call stack is:
Call Stack
# Time Memory Function Location
1 0.0001 633832 {main}( ) ../index.php:0
2 1.2230 12049888 menu_execute_active_handler( ) ../index.php:21
3 1.2231 12050840 call_user_func_array ( ) ../menu.inc:527
4 1.2231 12051176 quiz_user_results( ) ../menu.inc:527
5 1.2782 14183728 quiz_calculate_score( ) ../quiz.pages.inc:25
6 1.3035 14210184 _quiz_question_response_get_instance( ) ../quiz.module:2438

Going to a page the following message is then displayed:

"The module for the questiontype is not enabled" which appear to be generate in quiz_question_module_for_type() in quiz.module line 2470.

This may be a seperate problem but I'm fairly certain that both are being caused by a question related to the quiz having been deleted. Just before the line where the error is reported there is:

  if (!isset($question)) {
    $question = node_load($nid, $vid);
  }

  $constructor = $info[$question->type]['response provider'];
  $to_return = new $constructor($result_id, $question, $answer);

I suspect that either there should be a check if $question has been loaded or the code should not have got this far with a question that is no longer available.

I will investigate further and try to find the root cause and create a patch.

Comments

donaldp created an issue. See original summary.

donaldp’s picture

StatusFileSize
new1.82 KB

This fixes both the problems I was finding.
I probably should have named the patch file a bit better.
I should probably also add that this was a deleted multi-choice question on a single page of multichoice questions.

donaldp’s picture

Still had an issue with this when deleting quiz results so added an additional change around the code listed in comment 1.

djdevin’s picture

Hmm, the question I have is, should we allow questions to be deleted that are part of existing Quiz results? Wouldn't that mess up reporting, a lot?

donaldp’s picture

I did think that as well. The site I'm working on is still having content added and altered (off line) so I was not in control of what was being deleted and they are not worried about the reporing at present. However stopping questions that are referrenced from being deleted would probably be a good idea.

djdevin’s picture

Status: Active » Needs review

We can add this as a sanity check but I'll probably add a message like "Questions are missing from this result, calculations may be off etc."

gisle’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #3 fixes the problem.

As for #4: I think this is mainly going to be used during development and testing of quizzes (i.e. before they're put in front of real users), so I wouldn't worry to much about messed up reporting.

Maybe some caveats in README.md that deleting quizzes that are part of existing runs will mess up reporting + a sanity check as suggested in #6.

But I'll hate being stopped from doing this on a test site.

Remon’s picture

Patch in #3 works. Development was almost impossible before applying that patch!

djdevin’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new4.23 KB

Implemented sanity checks the OOP way by using broken/fallback classes , similar to how Views and some other Drupal contrib modules do it. In the future we can add warning or error handling to the forms but right now it's not really possible given how tightly coupled Questions are with nodes.

But for now, this will enable deletion and management of quizzes and results where their questions have been deleted.

djdevin’s picture

StatusFileSize
new7.78 KB
new3.55 KB

The last submitted patch, 10: fatal_error_class_name-2624264-10.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 10: tests.patch, failed testing.

djdevin’s picture

Status: Needs work » Needs review
StatusFileSize
new3.61 KB
djdevin’s picture

StatusFileSize
new5.44 KB

The last submitted patch, 13: tests.patch, failed testing.

djdevin’s picture

Status: Needs review » Fixed

Fixed. Thanks!

  • djdevin committed 5db165e on 7.x-5.x
    Issue #2624264 by djdevin, donaldp: Fatal Error: Class name must be a...

Status: Fixed » Closed (fixed)

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

shaktik’s picture

Thanks @djdevin