-
Bug
-
Resolution: Fixed
-
Minor
-
3.1.8
-
None
-
$plugin->release = '3.1.7 (Build - 2017042800)';
-
MOODLE_31_STABLE
-
MOODLE_34_STABLE
Stack trace from logs:
Default exception handler: Error writing to database Debug: Incorrect integer value: 'other_23731' for column 'choice_id' at row 1
|
INSERT INTO mdl_questionnaire_resp_single (response_id,question_id,choice_id) VALUES(?,?,?)
|
[array (
|
0 => '47006', 1 => '6041', 2 => 'other_23731',
|
)]
|
Error code: dmlwriteexception
|
* line 482 of /lib/dml/moodle_database.php: dml_write_exception thrown
|
* line 1259 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
|
* line 1305 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
|
* line 82 of /mod/questionnaire/classes/response/single.php: call to mysqli_native_moodle_database->insert_record()
|
* line 218 of /mod/questionnaire/classes/question/base.php: call to mod_questionnaire\\response\\single->insert_response()
|
* line 1721 of /mod/questionnaire/questionnaire.class.php: call to mod_questionnaire\\question\\base->insert_response()
|
* line 649 of /mod/questionnaire/questionnaire.class.php: call to questionnaire->response_insert()
|
* line 198 of /mod/questionnaire/questionnaire.class.php: call to questionnaire->print_survey()
|
* line 71 of /mod/questionnaire/complete.php: call to questionnaire->view()
|
, referer: https://mysite/mod/questionnaire/complete.php?id=30512
|
I was able to reproduce in a questionnaire that had a required Radio Buttons question, with an !other option (as part of a questionnaire that uses conditional branching - not sure if that's relevant) that was selected by the user who then omitted the actual Other content
This was fixed with following trivial patch:
diff --git a/classes/response/single.php b/classes/response/single.php
|
index bffb7e1..b04de36 100644
|
--- a/classes/response/single.php
|
+++ b/classes/response/single.php
|
@@ -79,7 +79,11 @@ class single extends base {
|
$record->question_id = $this->question->id;
|
$record->choice_id = isset($val) ? $val : 0;
|
if ($record->choice_id) {// If "no answer" then choice_id is empty (CONTRIB-846).
|
- return $DB->insert_record($this->response_table(), $record);
|
+ try {
|
+ return $DB->insert_record($this->response_table(), $record);
|
+ } catch (\dml_write_exception $ex) {
|
+ return false;
|
+ }
|
} else {
|
return false;
|
}
|