-
Bug
-
Resolution: Duplicate
-
Critical
-
None
-
2.1.1
-
moodle 2.1.0 (inplace upgraded from 1.9.12 via 2.0.3)
database postgres 8.4
Centos 5.6 x86_64
apache 2.2.3
php 5.3.3
-
PostgreSQL
-
MOODLE_21_STABLE
-
-
Easy
-
Accessing a forum discussion with enabled rating yields an error message due to an uncaught exception:
Output of /var/log/httpd/error_log:
Default exception handler:
Error reading from database Debug:
ERROR: column "ur.rating" must appear in the GROUP BY clause or be used in an aggregate function at character 194
SELECT r.itemid, r.component, r.ratingarea, r.contextid, AVG(r.rating) AS aggrrating, COUNT(r.rating) AS numratings, ur.id, ur.userid, ur.scaleid, ur.rating AS usersrating FROM mdl_rating r
LEFT JOIN mdl_rating ur ON
ur.contextid = r.contextid AND
ur.itemid = r.itemid AND
ur.component = r.component AND
ur.ratingarea = r.ratingarea AND
ur.userid = $1
WHERE r.contextid = $2 AND
r.itemid = $3 AND
r.component = $4 AND
r.ratingarea = $5
GROUP BY r.itemid, r.component, r.ratingarea, r.contextid, ur.id, ur.userid, ur.scaleid
ORDER BY r.itemid
[array (\n 0 => '15',\n 1 => '751',\n 2 => '25',\n 3 => 'mod_forum',\n 4 => 'post',\n)]
- line 393 of /lib/dml/moodle_database.php: dml_read_exception thrown
- line 232 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end()
- line 678 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
- line 585 of /rating/lib.php: call to pgsql_native_moodle_database->get_records_sql()
- line 5469 of /mod/forum/lib.php: call to rating_manager->get_ratings()
- line 271 of /mod/forum/discuss.php: call to forum_print_discussion()\n, referer: http://hostname/moodle/mod/forum/view.php?id=xxx
Other forums without rating seem to work fine
attempt to provide at least a workaround
In the query at moodle/rating/lib.php:570 the column ur.rating is not part of the GROUP BY section at the end (nor is it the target of one of the aggregation functions). It seems that at least postgresql is unhappy about that. By adding the ur.rating column to the GROUP BY postgres no longer complains (so attached patch). Unfortunately, I'm not familiar enough with the source code or database structure of the ratings module, so I'm not sure wether that workaround has any undesired or unwanted sideeffects.
It is noteworthy that ur.rating is part of the GROUP BY clause in what seems to be the equivalent query of moodle version 2.0.4 (moodle/rating/lib.php:290), in this section is also a comment indicating that the GROUP BY is only there to keep postgresql from complaining.
(Personal remark/Sidenote: There may be valid reasons to assume that only one line is returned by that query and hence no ambiguity is possible with respect to the aggregated column results. But I'm always a little bit weary about that and would prefer keeping the GROUP BY intact even if other RDBs seem to be less pedantic)