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

Activity chooser does not display if site contains invalid user

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      Prerequisites

      You will need to re-create the problem by manually altering db records, so an access and permission to update the database is required.

      1. On a fresh install, find the Guest user and manually set the user in the database as 'deleted'.
        • The guest user is the record in the user table with the username "guest".
        • You can run the following query
          • UPDATE mdl_user SET deleted = 1 WHERE username LIKE '%guest%';
      2. Manually remove the context of the guest user from the database.
        • You can run the following query
          • DELETE FROM mdl_context WHERE contextlevel = 30 AND instanceid IN (SELECT id FROM mdl_user WHERE username LIKE '%guest%');
      3. Purge the cache.

      Test 1

      1. Find the hash of the commit "MDL-69751 course: Handle missing guest user context" (ex. f47f244b8e777a98eaacd4b94ca3b2f469b0f542)
      2. Checkout to the specific commit by using the following command

      git checkout f47f244b8e777a98eaacd4b94ca3b2f469b0f542
      

      (assuming f47f244b8e777a98eaacd4b94ca3b2f469b0f542 it the commit hash of  "MDL-69751 course: Handle missing guest user context")

      1. Login as Admin.
      2. Create a Course.
      3. Go to the Course and turn editing on.
      4. Click on any 'Add an activity or resource' link to open the activity chooser.
      5. In the activity chooser:
        • confirm an error message "Coding error detected, it must be fixed by a programmer: The guest user context does not exist." is being displayed.

      Test 2

      We now need to get our branch back to normal. Run the following command:

      • testing the integration master branch (if not testing on the integration branch replace 'master' with the name of the pull master branch 'MDL-69751-master')

        git checkout master

      • testing the integration 3.10 branch (if not testing on the integration branch replace 'master' with the name of the pull 3.10 branch 'MDL-69751-310')

        git checkout MOODLE_310_STABLE
        

      • testing the integration 3.9 branch (if not testing on the integration branch replace 'master' with the name of the pull 3.9 branch 'MDL-69751-39')

        git checkout MOODLE_39_STABLE
        

      1. Login as Admin.
      2. Go to Site Administration and run the upgrade.
      3. After the upgrade is finished, create a Course.
      4. Go to the Course and turn editing on.
      5. Click on any 'Add an activity or resource' link to open the activity chooser.
      6. In the activity chooser:
        • confirm that the activity chooser works properly without any error messages.
      7. Check in the database whether the guest user has been properly restored using the following query :
        • SELECT deleted FROM mdl_user WHERE username LIKE '%guest%';
        • confirm the returned result is 0;
      8. Check in the database whether the guest user context exists using the following query:
        • SELECT * FROM mdl_context WHERE contextlevel = 30 AND instanceid IN (SELECT id FROM mdl_user WHERE username LIKE '%guest%');
        • confirm that the query returns a result.
      Show
      Prerequisites You will need to re-create the problem by manually altering db records, so an access and permission to update the database is required. On a fresh install, find the Guest user and manually set the user in the database as 'deleted'. The guest user is the record in the user table with the username "guest". You can run the following query UPDATE mdl_user SET deleted = 1 WHERE username LIKE '%guest%'; Manually remove the context of the guest user from the database. You can run the following query DELETE FROM mdl_context WHERE contextlevel = 30 AND instanceid IN (SELECT id FROM mdl_user WHERE username LIKE '%guest%'); Purge the cache. Test 1 Find the hash of the commit " MDL-69751 course: Handle missing guest user context" (ex. f47f244b8e777a98eaacd4b94ca3b2f469b0f542) Checkout to the specific commit by using the following command git checkout f47f244b8e777a98eaacd4b94ca3b2f469b0f542 (assuming f47f244b8e777a98eaacd4b94ca3b2f469b0f542 it the commit hash of  " MDL-69751 course: Handle missing guest user context") Login as Admin. Create a Course. Go to the Course and turn editing on. Click on any 'Add an activity or resource' link to open the activity chooser. In the activity chooser: confirm an error message "Coding error detected, it must be fixed by a programmer: The guest user context does not exist." is being displayed. Test 2 We now need to get our branch back to normal. Run the following command: testing the integration master branch (if not testing on the integration branch replace 'master' with the name of the pull master branch ' MDL-69751 -master') git checkout master testing the integration 3.10 branch (if not testing on the integration branch replace 'master' with the name of the pull 3.10 branch ' MDL-69751 -310') git checkout MOODLE_310_STABLE testing the integration 3.9 branch (if not testing on the integration branch replace 'master' with the name of the pull 3.9 branch ' MDL-69751 -39') git checkout MOODLE_39_STABLE Login as Admin. Go to Site Administration and run the upgrade. After the upgrade is finished, create a Course. Go to the Course and turn editing on. Click on any 'Add an activity or resource' link to open the activity chooser. In the activity chooser: confirm that the activity chooser works properly without any error messages. Check in the database whether the guest user has been properly restored using the following query : SELECT deleted FROM mdl_user WHERE username LIKE '%guest%'; confirm the returned result is 0; Check in the database whether the guest user context exists using the following query: SELECT * FROM mdl_context WHERE contextlevel = 30 AND instanceid IN (SELECT id FROM mdl_user WHERE username LIKE '%guest%'); confirm that the query returns a result.
    • Affected Branches:
      MOODLE_39_STABLE
    • Fixed Branches:
      MOODLE_39_STABLE
    • Pull 3.9 Branch:
    • Pull 3.10 Branch:
      MDL-69751-310
    • Pull Master Branch:
      MDL-69751-master
    • Story Points:
      3
    • Sprint:
      4.0 holding pattern 7

      Description

      1. That issue was not fixed by MDL-69079 patch in Moodle version 3.9.2+ (Build: 20200918)
      2. There is no guest user in  my moodle db.
      3. When you try add new activity in one course you see message "Invalid User" and  system log shows:

      [Sat Sep 19 09:35:52.096088 2020] [php:notice] [pid 17403] [client xxx.xxx.186.83:41180] Default exception handler: Invalid user Debug: SELECT id FROM {user} WHERE id = ? AND deleted = ?\n[array (\n 0 => '2305',\n 1 => 0,\n)]\nError code: invaliduser\n* line 1599 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown\n* line 1575 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()\n* line 6554 of /lib/accesslib.php: call to moodle_database->get_record()\n* line 113 of /course/classes/local/service/content_item_service.php: call to context_user::instance()\n* line 282 of /course/classes/local/service/content_item_service.php: call to core_course\\local\\service\\content_item_service->get_recommendations()\n* line 311 of /course/renderer.php: call to core_course\\local\\service\\content_item_service->get_content_items_for_user_in_course()\n* line 866 of /course/format/renderer.php: call to core_course_renderer->course_section_add_cm_control()\n* line 49 of /course/format/weeks/format.php: call to format_section_renderer_base->print_multiple_section_page()\n* line 290 of /course/view.php: call to require()\n, referer: https://moodle.x.x.x/course/view.php?id=1003

       

        Attachments

          Activity

            People

            Assignee:
            Geshoski Mihail Geshoski
            Reporter:
            jemartins José Eduardo Martins
            Peer reviewer:
            Peter Dias
            Integrator:
            Jake Dallimore
            Tester:
            Anna Carissa Sadia
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              9/Nov/20

                Time Tracking

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day
                1d