swot icon indicating copy to clipboard operation
swot copied to clipboard

Deleting a quiz sometimes does not delete it from the parent topic's "quizzes" array

Open lukas-shawford opened this issue 10 years ago • 0 comments

Not sure yet under what circumstances this occurs, but after deleting a quiz, the quiz pre-remove hook (/lib/quiz.js:135) sometimes fails to remove the quiz from its parent topic's "quizzes" array. This results in an error whenever you try to load the quiz hierarchy:

  TypeError: Cannot call method 'toObject' of null
    at /app/lib/quiz/quizService.js:200:29
    at Array.map (native)
    at Promise.promise.promiseDispatch (/app/node_modules/q/q.js:759:13)
    at Function._.map._.collect (/app/node_modules/underscore/underscore.js:97:56)
    at _fulfilled (/app/node_modules/q/q.js:797:54)
    at /app/lib/quiz/quizService.js:199:32
    at /app/node_modules/q/q.js:1184:26
    at self.promiseDispatch.done (/app/node_modules/q/q.js:826:30)
    at /app/node_modules/q/q.js:525:49
    at flush (/app/node_modules/q/q.js:108:17)

This essentially makes the site unusable from that point onward, since the quiz hierarchy gets loaded every time you visit the "My Quizzes" page.

The approximate sequence of events leading to the error was:

  1. In the "General" topic, I clicked "Create Quiz".
  2. I realized I was in the wrong topic; however, I didn't delete the quiz right away. Instead, I went back to "My Quizzes". (I didn't add any questions or specify a name.)
  3. I opened the quiz for editing again (the name got defaulted to "New Quiz", as expected).
  4. I deleted the quiz using the gear dropdown at the top right.
  5. It said the quiz got deleted successfully, but the "My Quizzes" page failed to load.

Need to figure out why the pre-remove hook didn't fire - or maybe it did fire, but in that case I would need to figure out why it didn't do what it was supposed to do. In the meantime, as a temporary safeguard, it may be a good idea to filter out any null quizzes inside quizService.getQuizzesAndSubtopics() instead of blindly calling quiz.toObject.

lukas-shawford avatar Sep 14 '14 01:09 lukas-shawford