Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.2
    • Fix Version/s: 2.2.1
    • Component/s: Questions
    • Labels:
    • Database:
      Any
    • Testing Instructions:
      Hide

      We need to verify that this code change does not cause any regressions.

      Logged in as a teacher, create and edit some questions in the question bank, and move them between categories, and make sure there are no errors.

      Show
      We need to verify that this code change does not cause any regressions. Logged in as a teacher, create and edit some questions in the question bank, and move them between categories, and make sure there are no errors.
    • Workaround:
      Hide

      Replace next function:

       public function having_cap($cap) {
              $contextswithcap = array();
              foreach ($this->allcontexts as $context) {
                  if (has_capability($cap, $context)) {
                      $contextswithcap[] = $context;
                  }
              }
              return $contextswithcap;
          }
      
      

      with:

       public function having_cap($cap) {
              $contextswithcap = array();
              foreach ($this->allcontexts as $context) {
                  if ($context!=NULL && has_capability($cap, $context)) {
                      $contextswithcap[] = $context;
                  }
              }
              return $contextswithcap;
          }
      
      
      Show
      Replace next function: public function having_cap($cap) { $contextswithcap = array(); foreach ($ this ->allcontexts as $context) { if (has_capability($cap, $context)) { $contextswithcap[] = $context; } } return $contextswithcap; } with: public function having_cap($cap) { $contextswithcap = array(); foreach ($ this ->allcontexts as $context) { if ($context!=NULL && has_capability($cap, $context)) { $contextswithcap[] = $context; } } return $contextswithcap; }
    • Affected Branches:
      MOODLE_22_STABLE
    • Fixed Branches:
      MOODLE_22_STABLE
    • Pull from Repository:
    • Pull Master Branch:
    • Rank:
      33660

      Description

      After upgrade I get "Coding error detected, it must be fixed by a programmer: PHP catchable fatal error" when try to view a course.

        Issue Links

          Activity

          Hide
          Michael de Raadt added a comment -

          The "Coding error detected..." message is relatively generic. It would be interesting to know how you traced it back to this function.

          We'll have a look at your proposed solution. Ideally contexts should not be null. This may indicate an error elsewhere in the code that it might not be wise to cover for with this change.

          Please continue trying to determine why this error is happening. If you have any third-party plugins you might want to selectively remove those to see if they are causing problems.

          Show
          Michael de Raadt added a comment - The "Coding error detected..." message is relatively generic. It would be interesting to know how you traced it back to this function. We'll have a look at your proposed solution. Ideally contexts should not be null. This may indicate an error elsewhere in the code that it might not be wise to cover for with this change. Please continue trying to determine why this error is happening. If you have any third-party plugins you might want to selectively remove those to see if they are causing problems.
          Hide
          Michael de Raadt added a comment -

          Hi, Petr.

          I'm not sure who to assign this to, if anyone at all, but I thought you might like to look at the solution provided.

          Micheal d;

          Show
          Michael de Raadt added a comment - Hi, Petr. I'm not sure who to assign this to, if anyone at all, but I thought you might like to look at the solution provided. Micheal d;
          Hide
          Tim Hunt added a comment -

          I don't understand where this NULL is coming from.

          Certainly I don't like the proposed fix. The bug is where the NULL $context is passed in. We should not change the code to ignore that. We need to catch where the problem arises and fix it at source.

          I can't work out how that can possibly by null. ...

          Show
          Tim Hunt added a comment - I don't understand where this NULL is coming from. Certainly I don't like the proposed fix. The bug is where the NULL $context is passed in. We should not change the code to ignore that. We need to catch where the problem arises and fix it at source. I can't work out how that can possibly by null. ...
          Hide
          Tim Hunt added a comment -

          With this change, the error message should occur when question_edit_contexts is constructed, which should help is track down the root cause of the problem.

          rodrigo, Are you able to test this patch, and let us know if it makes a difference? Thanks.

          Show
          Tim Hunt added a comment - With this change, the error message should occur when question_edit_contexts is constructed, which should help is track down the root cause of the problem. rodrigo, Are you able to test this patch, and let us know if it makes a difference? Thanks.
          Hide
          rodrigo added a comment - - edited

          I get this error with the patch applied:
          Can not find data record in database table context.
          Debug info: SELECT * FROM

          {context}

          WHERE id = ?
          [array (
          0 => '4872',
          )]
          Stack trace:
          line 1272 of \lib\dml\moodle_database.php: dml_missing_record_exception thrown
          line 1249 of \lib\dml\moodle_database.php: call to moodle_database->get_record_select()
          line 4803 of \lib\accesslib.php: call to moodle_database->get_record()
          line 5056 of \lib\accesslib.php: call to context::instance_by_id()
          line 1521 of \lib\questionlib.php: call to context->get_parent_contexts()
          line 1436 of \lib\questionlib.php: call to question_edit_contexts->__construct()
          line 3229 of \lib\navigationlib.php: call to question_extend_settings_navigation()
          line 2861 of \lib\navigationlib.php: call to settings_navigation->load_course_settings()
          line 601 of \lib\pagelib.php: call to settings_navigation->initialise()
          line 617 of \lib\pagelib.php: call to moodle_page->magic_get_settingsnav()
          line 132 of \blocks\settings\block_settings.php: call to moodle_page->__get()
          line 280 of \blocks\moodleblock.class.php: call to block_settings->get_content()
          line 232 of \blocks\moodleblock.class.php: call to block_base->formatted_contents()
          line 926 of \lib\blocklib.php: call to block_base->get_content_for_output()
          line 978 of \lib\blocklib.php: call to block_manager->create_block_contents()
          line 349 of \lib\blocklib.php: call to block_manager->ensure_content_created()
          line 6 of \theme\binarius\layout\general.php: call to block_manager->region_has_content()
          line 685 of \lib\outputrenderers.php: call to include()
          line 637 of \lib\outputrenderers.php: call to core_renderer->render_page_layout()
          line 196 of \course\view.php: call to core_renderer->header()

          After debug the problem is in
          SELECT * FROM mdl_context WHERE id = ? (4872)
          I've checked the table and there is no id 4872
          I guess some info has been corrupted after upgrade. I remember that I had to recreate all courses.
          Is posible regenerate mdl_context or a script to fix/check mdl_context ?
          I'm not an expert on moodle so I don't know the pourpose of this table

          Show
          rodrigo added a comment - - edited I get this error with the patch applied: Can not find data record in database table context. Debug info: SELECT * FROM {context} WHERE id = ? [array ( 0 => '4872', )] Stack trace: line 1272 of \lib\dml\moodle_database.php: dml_missing_record_exception thrown line 1249 of \lib\dml\moodle_database.php: call to moodle_database->get_record_select() line 4803 of \lib\accesslib.php: call to moodle_database->get_record() line 5056 of \lib\accesslib.php: call to context::instance_by_id() line 1521 of \lib\questionlib.php: call to context->get_parent_contexts() line 1436 of \lib\questionlib.php: call to question_edit_contexts->__construct() line 3229 of \lib\navigationlib.php: call to question_extend_settings_navigation() line 2861 of \lib\navigationlib.php: call to settings_navigation->load_course_settings() line 601 of \lib\pagelib.php: call to settings_navigation->initialise() line 617 of \lib\pagelib.php: call to moodle_page->magic_get_settingsnav() line 132 of \blocks\settings\block_settings.php: call to moodle_page->__get() line 280 of \blocks\moodleblock.class.php: call to block_settings->get_content() line 232 of \blocks\moodleblock.class.php: call to block_base->formatted_contents() line 926 of \lib\blocklib.php: call to block_base->get_content_for_output() line 978 of \lib\blocklib.php: call to block_manager->create_block_contents() line 349 of \lib\blocklib.php: call to block_manager->ensure_content_created() line 6 of \theme\binarius\layout\general.php: call to block_manager->region_has_content() line 685 of \lib\outputrenderers.php: call to include() line 637 of \lib\outputrenderers.php: call to core_renderer->render_page_layout() line 196 of \course\view.php: call to core_renderer->header() After debug the problem is in SELECT * FROM mdl_context WHERE id = ? (4872) I've checked the table and there is no id 4872 I guess some info has been corrupted after upgrade. I remember that I had to recreate all courses. Is posible regenerate mdl_context or a script to fix/check mdl_context ? I'm not an expert on moodle so I don't know the pourpose of this table
          Hide
          rodrigo added a comment -

          After more testing I've changed a little the code:

           public function get_parent_contexts($includeself = false) {
                  if (!$contextids = $this->get_parent_context_ids($includeself)) {
                      return array();
                  }
          
                  $result = array();
                  foreach ($contextids as $contextid) {
                      //$parent = context::instance_by_id($contextid, MUST_EXIST);
                  	$parent = context::instance_by_id($contextid, IGNORE_MISSING);
                  	if($parent!=NULL)
                      	$result[$parent->id] = $parent;
                  }
          
                  return $result;
              }
          

          So if the contextid is not in context table I don't return that contextid, now works again
          But the problem is that the context table has invalid data
          I think the best solution is recreate the table or try to find the missing data with a admin script.

          Show
          rodrigo added a comment - After more testing I've changed a little the code: public function get_parent_contexts($includeself = false ) { if (!$contextids = $ this ->get_parent_context_ids($includeself)) { return array(); } $result = array(); foreach ($contextids as $contextid) { //$parent = context::instance_by_id($contextid, MUST_EXIST); $parent = context::instance_by_id($contextid, IGNORE_MISSING); if ($parent!=NULL) $result[$parent->id] = $parent; } return $result; } So if the contextid is not in context table I don't return that contextid, now works again But the problem is that the context table has invalid data I think the best solution is recreate the table or try to find the missing data with a admin script.
          Hide
          Tim Hunt added a comment -

          I suspect what is going on is that you have some bad data in your DB.

          Specifically, I think you have a context where context.parent contains .../4872/... but there is no context with context.id = 4872. This should be impossible.

          Can you try following the advice on http://docs.moodle.org/20/en/How_to_rebuild_context_paths and see if that solves your problem?

          Show
          Tim Hunt added a comment - I suspect what is going on is that you have some bad data in your DB. Specifically, I think you have a context where context.parent contains .../4872/... but there is no context with context.id = 4872. This should be impossible. Can you try following the advice on http://docs.moodle.org/20/en/How_to_rebuild_context_paths and see if that solves your problem?
          Hide
          rodrigo added a comment - - edited

          You are right, after execute rebuild context paths all problems gone using old code.
          Maybe you can catch that exception and replace text to add a link to that page

          Show
          rodrigo added a comment - - edited You are right, after execute rebuild context paths all problems gone using old code. Maybe you can catch that exception and replace text to add a link to that page
          Hide
          Tim Hunt added a comment -

          Submitting the code change I did for integration, because it is an improvement.

          I won't try to change the exception message at this time. That would involve changes to the accesslib.php core library, and so is really a separate change.

          Show
          Tim Hunt added a comment - Submitting the code change I did for integration, because it is an improvement. I won't try to change the exception message at this time. That would involve changes to the accesslib.php core library, and so is really a separate change.
          Hide
          Sam Hemelryk added a comment -

          Thanks Tim - this has been integrated and tested now

          Show
          Sam Hemelryk added a comment - Thanks Tim - this has been integrated and tested now
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Whoever decided one week was worth 14 days had really one bad idea. Anyway, the nightmare is over, so thanks for your, once again, amazing contributions. Many, many thanks!

          Now... disconnect, relax and enjoy the next days, yay!

          Closing...ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Whoever decided one week was worth 14 days had really one bad idea. Anyway, the nightmare is over, so thanks for your, once again, amazing contributions. Many, many thanks! Now... disconnect, relax and enjoy the next days, yay! Closing...ciao

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: