Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-83028

Lesson essay - unserialize error on useranswer, backup/restore with student data dropping carriage returns ascii character 13

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.4
    • Backup, Lesson
    • None
    • MOODLE_404_STABLE

      We had an issue come up recently where all of the student responses and teacher feedbacks to lesson essays disappeared after backing up and restoring a course with student data. The core issue is that something in the backup/restore is dropping carriage returns (ascii 13) from the useranswer field in mdl_lesson_attempts, which is a field containing serialized data. This results in the string(s) in the restored serialized object being a different length than what is recorded, which in turn results in a "unserialize error at offset". This in turn results in the data not being output to the screen, and other effects (like grading recognition) being handled incorrectly because the attempt object never gets loaded.

      Here are the steps to reproduce the issue on a fresh copy of moodle.

      1. Build a fresh moodle instance with full debugging turned on. 
      2. Create one course. Create two accounts (teacher and student) and enroll them into the course in their respective roles.
      3. Log into the course as a teacher and create a lesson with a single page, essay question
      4. Log into the course as a student and answer the essay question in the lesson, hitting carriage return (enter) somewhere in your data at least once 
      5. Log into the course as an admin. Go into the lesson, then "grade essays" and you should see the attempt without any errors. Go into the attempt and again, you won't see any errors, and the student response will appear.
      6. As the admin, backup the course with student data
      7. After the backup is complete, restore the course with the student data, choosing "restore into this course" and "delete course first"
      8. Once the restore is complete, go into the lesson as teacher or admin and click "grade essays". You should see two errors appear, one relating to unserialize and the second relating to a missing property (graded). Click on the student essay to go into it. You will find that the student's response does not appear at all, and that the two errors appears there, too.

      Note that if you run the following SQL on the lesson attempt before and after the backup/restore, you will get a non-zero number before, and zero after (assuming you hit carriage return/enter at least once when submitting your essay response). This query basically shows you that the backup/restore is removing CHR(13).

      SELECT length(useranswer) - LENGTH(REPLACE(useranswer, chr(13), '')) as countchr13 from mdl_lesson_attempts where id = X;

      Of course, you will need to provide the correct ID for X. Note that the id will change after the restore.

      If I go into dbeaver AFTER the restore (while the problem is presenting) and edit the mdl_lesson_attempts useranswer field, and add a space/remove a space (anywhere), then save, it will fix the problem. The "fix" is technically because dbeaver is putting the CHR(13)s back into the data when you update the field. You can see this if you run the query above again after applying the fix.

      Note that while the problem as described above is specific to the student "answer" in the serialized object, it will also manifest on the teacher feedback (which is also part of the the serialized data in mdl_lesson_attempts.useranswer)

      Not sure if this is relevant, but my database is postgres and is using collate/ctype en_US.UTF-8. My environment is Windows, but we have seen the problem manifest on our Unix environments, too.

            Unassigned Unassigned
            jcoughli John Coughlin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.