Hi. I don't know if it's fair to call this a "bug", because the quiz module itself never hits this use case.

However, in my case, I'm wrapping quiz_take_page with another page callback that checks how many questions a few quizzes have before displaying which quiz to take.

A recent change in #2576419: Question count should exclude non gradable questions breaks this use case, because the call to quiz_get_number_of_questions upon submission of the last question prematurely sets the static cache, so when it grades, all kinds of PHP errors are thrown out.

Notice: Undefined property: stdClass::$choice_boolean in MultichoiceResponse->score() (line 888 of sites/all/modules/contrib_frozenversion/quiz/question_types/multichoice/multichoice.classes.inc).
Notice: Undefined property: stdClass::$alternatives in MultichoiceResponse->isAllWrong() (line 924 of sites/all/modules/contrib_frozenversion/quiz/question_types/multichoice/multichoice.classes.inc).

...And the score is wrong.

I'm not sure if this will be even supported, but having a 'donotcache' parameter for _quiz_question_get_instance and calling it in that mode within quiz_get_number_of_questions would be one approach...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

captainack created an issue. See original summary.

captainack’s picture

Issue summary: View changes

Well I worked around the problem by copying the old code that used to be in quiz_get_number_of_questions and using that instead.

It solved my problem. But I'm a little puzzled as to why. After looking at quiz_question_answering_form_validate(), I see _quiz_question_get_instance called with FALSE as use_cached, so the (presumably corrupt) cache entry should be overwritten. AFAICT This is called before anything, so there shouldn't be a problem.

Since I'm working around it and it currently shows no problems with basic quiz module usage, you can close this if it's not worth the trouble to investigate.

djdevin’s picture

Title: quiz_get_number_of_questions corrupts quiz instance static cache if called before quiz_take_page called » Refactor _quiz_question_get_instance
Status: Active » Needs work

_quiz_question_response_get_instance also had a ton of caching on it, which is now unnecessarily because of the level of caching in core (we are using nodes and the Entity API). That was addressed in #2470103: Refactor scoring system to use Entity and Question API

So we should fix this too anyway. There's even a comment that says "get rid of this in D7" so...

djdevin’s picture

Status: Needs work » Needs review
FileSize
2.86 KB

  • djdevin committed 1ffb219 on 7.x-5.x
    Issue #2592105 by djdevin, captainack: Refactor...
djdevin’s picture

Status: Needs review » Fixed

"Fixed"

This delegates to the built in Entity cache.

captainack’s picture

Sweet! Thanks Devin!

Status: Fixed » Closed (fixed)

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