Question edit displays "error getting category record"

Question edit displays "error getting category record"

by Vedran Mušica -
Number of replies: 14
I have huge problem: in every course question editing is not possible because of error "error getting category record". The only place where it works is frontpage questions.
Old questions (created before upgrade) are working in quizzes, but it is not possible to edit quiz nor is possible to edit question(s).

It affects teaching staff and admins, so problem is global.

I have moodle 1.9.2+, build 20080820, upgraded from v1.8.4+.

I need some fix as soon as possible, as teachers use quizzes all the time....


Best regards,
Vedran

Average of ratings: -
In reply to Vedran Mušica

Re: Question edit displays "error getting category record"

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
During the upgrade, were any errors reported? (You can find a copy of everything ouput during the upgrade in moodledata/upgradelogs.)

And can you run whatever script your database provides for checking tables for corruption. For example: Administration_FAQ#How_do_I_repair_a_corrupted_Moodle_database.3F
In reply to Tim Hunt

Re: Question edit displays "error getting category record"

by Vedran Mušica -
There were no errors... that's why I'm surprised it happened.
I'll see if database needs repairing.

Thank You.
In reply to Vedran Mušica

Re: Question edit displays "error getting category record"

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The query that is failing is
SELECT * FROM mdl_question_categories
 WHERE contextid = '123'
 ORDER BY sortorder, name
 LIMIT 1
You might like to try that in PHPMyAdmin, or equivalent and see what error is occurring. The actual contextid number does not matter - it does not matter whether any records are matched, just that a query of this general form can be executed without errors.
In reply to Tim Hunt

Re: Question edit displays "error getting category record"

by Vedran Mušica -
Query works, no errors produced, entry retrieved...
In reply to Tim Hunt

Re: Question edit displays "error getting category record"

by Vedran Mušica -
This doesn't work on PostgreSQL database...
In reply to Vedran Mušica

Re: Question edit displays "error getting category record"

by Vedran Mušica -
Info update:
This is moodle v1.9.2+, upgraded from 1.8.4.
Database is PostgreSQL 8.1.

No errors were reported during upgrade.

On frontpage questions work, on courses don't....
It isn't related to roles, as it works for admin on frontpage, and not in courses (no course has access to questions).
In reply to Vedran Mušica

Re: Question edit displays "error getting category record"

by Vedran Mušica -
Error found.

In questionlib.php, around line 1892 is this.
if (!$categoryrs = get_recordset_select("question_categories", "contextid = '{$context->id}'", 'sortorder, name', '*', '', 1)) {
error('error getting category record');
} else {

but, when this error is commented, everything works fine. What could be reason for that?

Oh, yes, every category for questions exist - even default one.

Regards,
Vedran
In reply to Vedran Mušica

Re: Question edit displays "error getting category record"

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes, that is the query I extracted from the code and asked you to test in isolation. Just ignoring the error does not seem like a good plan to me. I am sprised that the problem occurs in Postgres, because I use Postgres for my development, and so would expect to notice problems like this, and I haven't.

Anyway it would be better to fix the query so that it works.
In reply to Tim Hunt

Re: Question edit displays "error getting category record"

by Vedran Mušica -
This is my plan, exactly.
I know that killing this error report for it self isn't a permanent solution, and I will continue to look for real error.

When I find it - and I will - I'll post here the reason and (possible) solution.

And my opinion is that the problem might be in upgrading.
I have another moodle installation (same database, v1.9.2) which had clean install (no upgrading) and it works just fine.

Best regards,
Vedran
In reply to Vedran Mušica

Re: Question edit displays "error getting category record"

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
One thing to check is the database tables in the upgraded version with the ones in the new install. Do they have the same columns with the same types?

Thank you for taking the time to investigate this issue and report your progress here. It is people like you that help make Moodle a robust platform.
In reply to Tim Hunt

Re: Question edit displays "error getting category record"

by Vedran Mušica -
I have checked database, and it is properly upgraded. I have one 1.8.4 installation (old test) and database tables for questions are different. In my new test installation (1.9.2+) database look exactly the same as in production one.

I will make diff scans in files, maybe there is some problem, or some file hasn't been copied well...

Regards,
Vedran
In reply to Vedran Mušica

Re: Question edit displays "error getting category record"

by Vedran Mušica -
Found another problem, probably related to this.

Multianswer (cloze) questions is not possible to edit. I get "Could not update question!".

Trying to find error, but I can't....
In reply to Vedran Mušica

Re: Question edit displays "error getting category record"

by Vedran Mušica -
Found error place, don't know how to fix it:
in questiontype.php, line (around) 285 is this:

if (!update_record('question', $question)) {
error('Could not update question!');
}

The problem is that I can't find ANY problem with $question data, except it is Cloze...

Any and every help with this is appreciated!


Regards,
Vedran