kolibri icon indicating copy to clipboard operation
kolibri copied to clipboard

reload on connect in quizsummarypage; avoid possible error w/ missing…

Open nucleogenesis opened this issue 1 year ago • 6 comments

Summary

Closes #12388

I was only able to replicate the error described there by @AlexVelezLl when I forced specifically a 502 error within the size endpoint's handler. I don't know any way that a 502 would come through unless the server is disconnected somehow during the page load.

I could not replicate it naturally, however, so I cannot be 100% this addresses the issue at hand here.

But, ultimately, what it came down to was that if the page got a 502 error, it would show the proper "disconnected" snackbar & backdrop. In this case, the value used this.quizId was not yet initialized.

The change here ensures that when the user regains connection to the server, their page will reload, hopefully successfully.


One thing of concern is that if there is a way in which we could end up getting some kind of unjustified 502, then this could just result in an infinite loop of failing to connect and reloading.

The only way that I can think of that the size endpoint's handler would cause a 502 is if it's crashing the server. I've made some large quizzes during development on EQM and I've not had any issues with it and trying it didn't help replicate the issue.

Without some kind of stack trace for the error from a naturally occurring replication of the error this will be hard to debug, as there are several calls within that could cause the failure:

    @action(detail=False)
    def size(self, request, **kwargs):
        exams, draft_exams = self.filter_querysets(
            self.get_queryset(), self.get_draft_queryset()
        )
        exams_sizes_set = []
        for exam in list(exams) + list(draft_exams):
            quiz_size = {}

            quiz_nodes = ContentNode.objects.filter(
                id__in=[question["exercise_id"] for question in exam.get_questions()]
            )

            quiz_size[exam.id] = total_file_size(quiz_nodes)
            exams_sizes_set.append(quiz_size)

        return Response(exams_sizes_set)

Also worth noting that my first thought was to force an error within the function there, but that just resulted in the expected 400 Bad request rather than the 502 that is the direct cause of this issue.

Reviewer guidance

Code review

  • Is there any kind of additional handing I should add in the size handler?
  • Any thoughts on how to better replicate this particular issue -- are there any quirks to our disconnection handling that might come into play here?

QA

Path 1: Fake replication

  • With Network Throttling enabled, click to view a Quiz's details (click it's name link on the quiz list page). Throttling will help buy you time to kill your server in the next step :)
  • Then, quickly kill your server kolibri stop, causing the backend to no longer be available
  • Restart the Kolibri server, click to reconnect on the snackbar message in your browser, and the page should reload when you reconnect successfully
  • Now you should be able to delete the quiz without issue

Path 2: Possibly replicate it naturally

  • Maybe try once more with a very large quiz w/ lots of exercises in it that would have a large size
  • Don't do the "kill your server" thing manually and see if you can get it to naturally occur that you get a 502 somehow?

nucleogenesis avatar Aug 12 '24 21:08 nucleogenesis

Hi @nucleogenesis, following the directions in 'Path 1: Fake replication' I managed to actually replicate the original issue that is - I can see the quiz details page with "Resource not found on device" shown and I can't delete the quiz after having successfully restarted the server. Only if I manually refresh the entire page, then I can delete it. So if we consider that a valid testing scenario, then we've not fixed the original issue since from the perspective of a normal user of Kolibri we are still getting in the edge-case scenario where we can't delete the quiz with missing resources for no obvious reason. Here's a video of what I am observing:

https://github.com/user-attachments/assets/1c59b7d9-d5ff-472c-84a9-58109f08b62b

Logs: logs.zip

pcenov avatar Aug 13 '24 12:08 pcenov

@pcenov I've updated the PR so that the deletion modal uses the always present quizId value from the URL itself. This ensures that the modal being submitted will always work.

@rtibbles @AlexVelezLl -- I've updated the QuizSummaryPage a bit here. We were duplicating the fetch from the backend to get data we already had available by way of the classSummary store. So the component got the same data two different ways and used them differently.

My changes consolidate them into one exam property derived from classSummary/examMap, then uses the exam utils fetchExamWithContent function to be sure we're getting the content in the right shape. I think that we could probably just derive this from the classSummary/contentNodeMap but I figured I'd get feedback on this first as I think the changes here should sufficiently resolve the issue this PR targets.

nucleogenesis avatar Aug 26 '24 20:08 nucleogenesis

Hi @nucleogenesis - I confirm that now it's possible to delete a quiz while the 'Resource not found on device' message is displayed:

https://github.com/user-attachments/assets/7b9259b5-2d8b-4d6b-a5d9-7bc1922642fb

I can also see the missing resources loaded correctly when I manually refresh the page after the successful server restart:

https://github.com/user-attachments/assets/ec838c0a-bb54-41d9-bcd0-b61649f3909b

pcenov avatar Sep 04 '24 13:09 pcenov

As a final manual test here before we merge, @pcenov could you:

  1. Install 0.16
  2. Create a quiz on 0.16.
  3. Upgrade to the asset in this PR.
  4. Navigate to the quiz summary page for a specific quiz under plan.
  5. Confirm that the questions all display correctly.

rtibbles avatar Sep 16 '24 15:09 rtibbles

Hi @rtibbles - I confirm that there is a regression when opening a quiz created in 0.16:

https://github.com/user-attachments/assets/62e05b16-2d2b-4ce1-b035-6865ded87d4d

I'm seeing the following error in the console:

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at ManageExamModals.vue:95:1
    at QuizSummaryPagevue_type_script_lang_js_toConsumableArray (ManageExamModals.vue:95:1)
    at index.vue:116:1
    at Array.reduce (<anonymous>)
    at Sub.selectedQuestions (index.vue:115:1)
    at Watcher.get (vue.runtime.esm.js:4495:25)
    at Watcher.evaluate (vue.runtime.esm.js:4597:21)
    at Sub.selectedQuestions (vue.runtime.esm.js:4851:17)
    at Sub.QuizSummaryPagevue_type_template_id_f77f4f98_scoped_true_render (index.vue:1:1036)
    at vue-composition-api.mjs:1940:35

Here's the entire home folder: kolibri.zip

pcenov avatar Sep 18 '24 11:09 pcenov

@pcenov I've updated the PR and two things to note:

  • The most recently reported issue no longer exists in 0.18 and since this is no longer targeting 0.17 it's no longer fixable.
  • Because of some of those changes made to QuizSummaryPage, I've reapplied the fixes that I had for being able to delete a quiz when things don't load correctly on the QuizSummaryPage.

Could you test the scenarios again mentioned in the reviewer's guidance?

nucleogenesis avatar Dec 05 '24 23:12 nucleogenesis

Hi @nucleogenesis - could you check why the build checks have not passed yet and there are no new build artefacts for this PR?

pcenov avatar Dec 06 '24 11:12 pcenov

@pcenov I tried re-running the jobs but they are just sitting there pending still. Will see if @rtibbles knows where things may have gone sideways next week.

nucleogenesis avatar Dec 06 '24 21:12 nucleogenesis

Hi @nucleogenesis - I see that there are new build artifacts now - is it ready for testing?

pcenov avatar Dec 13 '24 08:12 pcenov

Hi @nucleogenesis,

  1. It's still not possible to see the questions of a quiz created in 0.16 (when editing it), and not possible to copy that quiz, so the regression concern raised by @rtibbles is still valid for 0.18:

https://github.com/user-attachments/assets/75774d7d-911a-4964-82b9-ffe0a077fd4f

  1. I confirm that the user is being able to delete a quiz when things don't load correctly on the QuizSummaryPage.

pcenov avatar Dec 16 '24 16:12 pcenov

@pcenov thank you!

I spoke w/ @rtibbles about the issue of not seeing the questions when editing a quiz from 0.16

In 0.17, Richard introduced two separate models - an Exam and a DraftExam.

Prior to this, we only had Exam.

Users are only able to edit a DraftExam - so when a new exam is created in >=0.17 the user is creating a DraftExam - they can edit this until they start the exam.

One reason for this is that the DraftExam cannot be synced so we can never run into an situation like:

  • Device A creates an Exam, does not start it
  • Device B syncs that Exam from Device A, then starts it
  • Device A now edits the Exam

So since the Exam was created as an Exam in 0.16, when the Kolibri is upgraded, it is still an Exam and not a DraftExam, thus it cannot be edited and the questions are not listed in the "Edit Quiz" page.

nucleogenesis avatar Dec 16 '24 20:12 nucleogenesis

@pcenov @rtibbles I've fixed the bug w/ the copying of <0.17.x quizzes so should be ready for final batch of QA & code review - also confirmed that those copies can be edited.

nucleogenesis avatar Dec 17 '24 00:12 nucleogenesis

Hi @nucleogenesis - I confirm that copying of a quiz created in 0.16 is working fine in 0.18 (given the known issue that the questions are not visible initially). The copies can be edited too.

pcenov avatar Dec 17 '24 12:12 pcenov