Questions failing to be saved, with the error. “Error Reading from Database”

Questions failing to be saved, with the error. “Error Reading from Database”

by John Kometz -
Number of replies: 10

We have had a strange problem with Essay type questions not saving. When the a student goes to submit their exam, they get an error. Upon looking at the questions you can isolate the error to a some of the essay type questions, however the failure is random. A given question will work sometimes but not others, with no apparent pattern.

The background: this is on a new install of moodle 2.0 (2.0.1+ (Build: 20101229) ) using a postgres database. We are using a hardware load balancer for the application, and the database is on 2 servers using a “master-slave” setup.

Our first guess was issues with the questions, since they had been imported from a course in blackboard CE 8 using a bit of a convoluted procedure. But we re-created the questions (created them 1 at a time) in the question bank, but this didn't help.

We then looked at the database and found it was throwing errors like the following

2011-02-04 15:55:25 MST ERROR: invalid input syntax for integer: "random8010- [text of the students response to the question]”

Which suggests that the system is trying to stuff text data into an integer field of the database. We think this could be a corruption issue, or a more systemic one, but are at a loss as to what to check next.

Any help would be appreciated.

Average of ratings: -
In reply to John Kometz

Re: Questions failing to be saved, with the error. “Error Reading from Database”

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Strings like that are inserted into the mdl_question_states.answer column, which should be of type TEXT. Can you check:

  1. the type of that column in your database.
  2. turn on Debugging, then the error message should include the full SQL that Moodle is trying to execute, and verify which column it is trying to insert that value into.
In reply to Tim Hunt

Re: Questions failing to be saved, with the error. “Error Reading from Database”

by John Kometz -

Tim,

We did as you suggested and the database table definision is (it looks right):

moodle=# \d mdl_question_states
Table "public.mdl_question_states"
Column   |     Type      |                            Modifiers

------------+---------------+------------------------------------------------------------------
id         | bigint        | not null default
nextval('mdl_question_states_id_seq'::regclass)
attempt    | bigint        | not null default 0
question   | bigint        | not null default 0
seq_number | integer       | not null default 0
answer     | text          | not null
timestamp  | bigint        | not null default 0
event      | smallint      | not null default 0
grade      | numeric(12,7) | not null default 0
raw_grade  | numeric(12,7) | not null default 0
penalty    | numeric(12,7) | not null default 0
Indexes:
"mdl_quesstat_id_pk" PRIMARY KEY, btree (id)
"mdl_quesstat_att_ix" btree (attempt)
"mdl_quesstat_que_ix" btree (question)

 

And the following is a sample error we get after turning de-bugging on:

[10-Feb-2011 11:25:39] Default exception handler: Error reading from
database Debug: ERROR:  invalid input syntax for integer:
"random9163-<p>bohemian rhapsody</p>
<p> </p>"
SELECT * FROM mdl_question WHERE id = $1
[array (
0 => 'random9163-<p>bohemian rhapsody</p>
<p> </p>',
)]
* line 391 of /lib/dml/moodle_database.php: dml_read_exception thrown
* line 229 of /lib/dml/pgsql_native_moodle_

database.php: call to
moodle_database->query_end()
* line 669 of /lib/dml/pgsql_native_moodle_database.php: call to
pgsql_native_moodle_database->query_end()
* line 1256 of /lib/dml/moodle_database.php: call to
pgsql_native_moodle_database->get_records_sql()
* line 1228 of /lib/dml/moodle_database.php: call to
moodle_database->get_record_sql()
* line 1208 of /lib/dml/moodle_database.php: call to
moodle_database->get_record_select()
* line 244 of /question/type/random/questiontype.php: call to
moodle_database->get_record()
* line 1297 of /lib/questionlib.php: call to
random_qtype->restore_session_and_responses()
* line 1096 of /lib/questionlib.php: call to restore_question_state()
* line 507 of /mod/quiz/attemptlib.php: call to question_load_states()
* line 61 of /mod/quiz/review.php: call to
quiz_attempt->load_question_states()
John
In reply to John Kometz

Re: Questions failing to be saved, with the error. “Error Reading from Database”

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Ah, this looks like MDL-26236.

In reply to Tim Hunt

Re: Questions failing to be saved, with the error. “Error Reading from Database”

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

And that prompts me to try to fix this bug.

I think https://github.com/timhunt/moodle/commit/c991ecb49d67eddd0d74be7d009f82b4571f143bis the correct fix, but I would really like some people to test this before a push a change that fundamental onto the stable branch. If you can test it, that would be a big help. Thanks.

In reply to Tim Hunt

Re: Questions failing to be saved, with the error. “Error Reading from Database”

by John Kometz -

Tim,

We applied this to our dev box,; on initial testing it fixed our problem, and didn't break any of our other exams. We have applied the fix to our beta box and intend on running a number of submissions at it over the next week.

I will let you know how it goes.

Thanks for your help.

John

In reply to John Kometz

Re: Questions failing to be saved, with the error. “Error Reading from Database”

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Thanks for testing.

Actually, I got impatient earlier today, and reviewed the code again and, then sent it off to be included in this week's weekly build, so hopefully you won't now find any problems.

In reply to Tim Hunt

Re: Questions failing to be saved, with the error. “Error Reading from Database”

by John Kometz -

Well we did find something that appears to be related.

You can now submit the exams properly however in some cases (approximately half of the class in our case) those questions do not show properly in the results table, or the manual grade page.

As an example of one student, note the attached clip. The first 10 questions (were multiple choice) list properly, however the last 7 (randomly generated essay). list as just "--" where all these questions have been answered, and should have a "Requires grading" link. You can work around this by cliking the "review attempt" and overriding the grade, but this is a very round about way to do the grading.

I should note that you cannot access these submissions through the manual marking page either.

John

Attachment quiz_error.GIF
In reply to John Kometz

Re: Questions failing to be saved, with the error. “Error Reading from Database”

by John Kometz -

It appears that the 2.02  patch fixes this issue, so no need to look further.

John

In reply to John Kometz

Re: Questions failing to be saved, with the error. “Error Reading from Database”

by Linda Erzah -

Is there a similar fix for Moodle 1.9.8?

In reply to Linda Erzah

Re: Questions failing to be saved, with the error. “Error Reading from Database”

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Probably upgrading to 1.9.12.