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

Problem restoring question categories when source and target contexts match

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.11.5
    • 3.10.7, 3.11.3, 4.0
    • Backup, Questions
    • MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_400_STABLE
    • MOODLE_311_STABLE
    • Hide

      Pre-requisites

      1. Able to run bash and git commands (surely mac and unix only).
      2. Able to patch and edit files
      3. This test has to be run for the following branches:
        1. MOODLE_311_STABLE
        2. master
      4. Use PostgreSQL for the testing below (one database is enough).

      Before the patch

      1. Run this to ensure the important files are clean:

        git checkout mod/quiz/tests/restore_attempt_test.php \
            mod/quiz/tests/fixtures/question_attempts_missing_users.mbz
        

      2. Checkout the branch being tested (BEFORE patch).
      3. Init PHPUnit with:

        php admin/tool/phpunit/cli/init.php
        

      4. Apply the pre_calculate_test.patch patch with:

        patch -p1 < /path/to/pre_calculate_test.patch
        

      5. Run this test and annotate the number (we'll need it later, we have called it XXX):

        vendor/bin/phpunit mod/quiz/tests/restore_attempt_test.php
        

      6. Copy hack_backup_file_for_mdl_72950.sh to the site dir root.
      7. Run this command, replacing the XXX by the number annotated 2 steps above, to prepare the backup file to reproduce the error:

        bash hack_backup_file_for_mdl_72950.sh XXX
        

      8. Edit the mod/quiz/tests/restore_attempt_test.php file and remove the line that says: "echo "Please, use this number...". Save changes.
      9. Run this test again:

        vendor/bin/phpunit mod/quiz/tests/restore_attempt_test.php
        

        (Important note, you only can run the command once, if want to run it again, then all the steps need to be executed or the test will pass).

      1. Verify that it fails with message: "Failed asserting that false is true".

      After the patch

      1. Run this to ensure the important files are clean:

        git checkout mod/quiz/tests/restore_attempt_test.php \
            mod/quiz/tests/fixtures/question_attempts_missing_users.mbz
        

      2. Checkout the branch being tested (AFTER patch).
      3. Init PHPUnit with:

        php admin/tool/phpunit/cli/init.php
        

      4. Apply the post_calculate_test.patch patch with:

        patch -f -p1 < /path/to/post_calculate_test.patch
        

        It's OK if the following error is displayed: "1 out of 2 hunks FAILED – saving rejects to file mod/quiz/tests/restore_attempt_test.php.rej"

      5. Repeat steps 5-9 from the previous section.
      6. Verify that last point, instead of failing, as was happening before the patch, now passes ok.
      Show
      Pre-requisites Able to run bash and git commands (surely mac and unix only). Able to patch and edit files This test has to be run for the following branches: MOODLE_311_STABLE master Use PostgreSQL for the testing below (one database is enough). Before the patch Run this to ensure the important files are clean: git checkout mod/quiz/tests/restore_attempt_test.php \ mod/quiz/tests/fixtures/question_attempts_missing_users.mbz Checkout the branch being tested (BEFORE patch). Init PHPUnit with: php admin/tool/phpunit/cli/init.php Apply the pre_calculate_test.patch patch with: patch -p1 < /path/to/pre_calculate_test.patch Run this test and annotate the number (we'll need it later, we have called it XXX): vendor/bin/phpunit mod/quiz/tests/restore_attempt_test.php Copy hack_backup_file_for_mdl_72950.sh to the site dir root. Run this command, replacing the XXX by the number annotated 2 steps above, to prepare the backup file to reproduce the error: bash hack_backup_file_for_mdl_72950.sh XXX Edit the mod/quiz/tests/restore_attempt_test.php file and remove the line that says: "echo "Please, use this number...". Save changes. Run this test again: vendor/bin/phpunit mod/quiz/tests/restore_attempt_test.php (Important note, you only can run the command once, if want to run it again, then all the steps need to be executed or the test will pass). Verify that it fails with message: "Failed asserting that false is true". After the patch Run this to ensure the important files are clean: git checkout mod/quiz/tests/restore_attempt_test.php \ mod/quiz/tests/fixtures/question_attempts_missing_users.mbz Checkout the branch being tested (AFTER patch). Init PHPUnit with: php admin/tool/phpunit/cli/init.php Apply the post_calculate_test.patch patch with: patch -f -p1 < /path/to/post_calculate_test.patch It's OK if the following error is displayed: " 1 out of 2 hunks FAILED – saving rejects to file mod/quiz/tests/restore_attempt_test.php.rej " Repeat steps 5-9 from the previous section. Verify that last point, instead of failing, as was happening before the patch, now passes ok.

      This has been detected while testing MDL-72743

      It seems that there is a (rare, coincidental, but real) issue in the code in charge of restoring the question categories and map them to the target course.

      It happens when a contextid in the source course (coming in the backup file) matches the context of a existing contextid in the target course AND when both contexts belongs to the same course (or an activity in the same course).

      Again, rare, yes, but 100% possible and reproducible. Also, while it has been possible to reproduce it with Oracle... the problem is the same for all databases.

      The original details commented @ MDL-72743 follow, explaining the problem:

      1) The backup file (that is 100% correct) comes with:

      • a course, with original contextid 29.
      • a quiz activity, with original context 31

      2) Of course the 2 question categories at course level also have 29 and the quiz ones 31.

      3) The test then creates a new course that is going to be the restore target.

      4) That course, by absolutely crazy coincidence (we don't support random sequence seeds in Oracle), is created with contextid 31 in target site.

      5) When restore perform the prechecks... it:

      • picks the question categories at course level (originally with contextid 29), detects 2, and, correctly, decides that their target contextid is going to be 31 (the target course, how not.
      • picks the question categories at activity level (originally with context 31), but it now detects incorrectly 4, because the previous step has updated the original 29s to 31s too.
      • Of course, those 4 categories do include 2 top categories... so the precheck fails.

      To reproduce it, just search codebase for MDL-72950, remove the skip test condition and, with Oracle, run vendor/bin/phpunit mod/quiz/tests/restore_attempt_test.php a few times.

            stronk7 Eloy Lafuente (stronk7)
            stronk7 Eloy Lafuente (stronk7)
            Tim Hunt Tim Hunt
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Angelia Dela Cruz Angelia Dela Cruz
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours, 35 minutes
                3h 35m

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