Merging Course error - Coding error detected

Merging Course error - Coding error detected

by Russ H -
Number of replies: 5

We are trying to import a section from one course into another. We tried using the import function and the restore into an existing course and are getting the error below. Has anyone else encountered this?  We are running: Moodle 3.2.1 (Build: 20170109) Version 2016120501

Notice: Trying to get property of non-object in /var/www/moodle/backup/moodle2/restore_stepslib.php on line 4477

Coding error detected, it must be fixed by a programmer: Invalid context id specified context::instance_by_id()

More information about this error
Debug info:
Error code: codingerror
Stack trace:

    line 5477 of /lib/accesslib.php: coding_exception thrown
    line 4477 of /backup/moodle2/restore_stepslib.php: call to context::instance_by_id()
    line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_create_categories_and_questions->process_tag()
    line 103 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()
    line 178 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk()
    line 91 of /backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk()
    line 148 of /backup/util/xml/parser/processors/simplified_parser_processor.class.php: call to restore_structure_parser_processor->postprocess_chunk()
    line 92 of /backup/util/xml/parser/processors/progressive_parser_processor.class.php: call to simplified_parser_processor->process_chunk()
    line 190 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()
    line 278 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()
    line ? of unknownfile: call to progressive_parser->end_tag()
    line 179 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()
    line 158 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()
    line 110 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()
    line 181 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
    line 177 of /backup/util/plan/base_plan.class.php: call to base_task->execute()
    line 167 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
    line 335 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
    line 162 of /backup/import.php: call to restore_controller->execute_plan()
   
   

Thank you in advance!   

Average of ratings: -
In reply to Russ H

Re: Merging Course error - Coding error detected

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The first (and easiest) thing I would check... are there any optional activities, resources, blocks etc. that have been added to the source Moodle that are not in the destination Moodle? If so, un-tick those items when taking the backup and try again. 

In reply to Howard Miller

Re: Merging Course error - Coding error detected

by Russ H -

Hi Howard,

Thanks for the response. The courses are being joined on the same installation of Moodle. Both courses share the same activity types. I even tried importing only a section heading and a label and it still threw the same error.



In reply to Russ H

Re: Merging Course error - Coding error detected

by Russ H -

As an update, we were able to determine that the problem may be related to importing questions with tags.


Notice: Trying to get property of non-object in /var/www/html/moodle/backup/moodle2/restore_stepslib.php on line 4481

Coding error detected, it must be fixed by a programmer: Invalid context id specified context::instance_by_id()

More information about this error

Debug info:
Error code: codingerror
Stack trace:
  • line 5137 of /lib/accesslib.php: coding_exception thrown
  • line 4481 of /backup/moodle2/restore_stepslib.php: call to context::instance_by_id()
  • line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_create_categories_and_questions->process_tag()
  • line 103 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()
  • line 178 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk()
  • line 91 of /backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk()
  • line 148 of /backup/util/xml/parser/processors/simplified_parser_processor.class.php: call to restore_structure_parser_processor->postprocess_chunk()
  • line 92 of /backup/util/xml/parser/processors/progressive_parser_processor.class.php: call to simplified_parser_processor->process_chunk()
  • line 190 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()
  • line 278 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()
  • line ? of unknownfile: call to progressive_parser->end_tag()
  • line 179 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()
  • line 158 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()
  • line 110 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()
  • line 181 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
  • line 177 of /backup/util/plan/base_plan.class.php: call to base_task->execute()
  • line 167 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
  • line 335 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
  • line 162 of /backup/import.php: call to restore_controller->execute_plan()


   4460
   4461     protected function process_tag($data) {
   4462         global $CFG, $DB;
   4463
   4464         $data = (object)$data;
   4465         $newquestion = $this->get_new_parentid('question');
   4466         $questioncreated = (bool) $this->get_mappingid('question_created', $this->get_old_parentid('question'));
   4467         if (!$questioncreated) {
   4468             // This question already exists in the question bank. Nothing for us to do.
   4469             return;
   4470         }
   4471
   4472         if (core_tag_tag::is_enabled('core_question', 'question')) {
   4473             $tagname = $data->rawname;
   4474             // Get the category, so we can then later get the context.
   4475             $categoryid = $this->get_new_parentid('question_category');
   4476             if (empty($this->cachedcategory) || $this->cachedcategory->id != $categoryid) {
   4477                 $this->cachedcategory = $DB->get_record('question_categories', array('id' => $categoryid));
   4478             }
   4479             // Add the tag to the question.
   4480             core_tag_tag::add_item_tag('core_question', 'question', $newquestion,
   4481                     context::instance_by_id($this->cachedcategory->contextid),
   4482                     $tagname);
   4483         }
   4484     }


Has anyone encountered this error before? Is there a clean way to delete all of the tags from a question bank, except for doing it manually?

cleardot.gif

In reply to Russ H

Re: Merging Course error - Coding error detected

by Russ H -

Could this be related to this earlier bug?

https://tracker.moodle.org/browse/MDL-46791

In reply to Russ H

Re: Merging Course error - Coding error detected

by Pinky Sharma -

We are also getting this error in Moodle 3.2. It seems when there is a question with tags and 'Enable tags functionality' setting is enable, it again try to add the tag to the question and throw error. But if tags functionality is disable, course imported successfully without throwing any error.

@Russ Instead of deleting tags from a question, disable tags functionality from 'Advanced features' before import. This worked for me.

Average of ratings: Useful (1)