gjbarnard / moodle-format_topcoll

Collapsed Topics course format for Moodle.
http://docs.moodle.org/en/Collapsed_Topics_course_format
GNU General Public License v3.0
35 stars 60 forks source link

Database error (PostgreSQL) when creating a new course #145

Open anieminen opened 1 year ago

anieminen commented 1 year ago

Describe the bug We have a large Moodle with over 70000 users using PostgreSQL database. Creating a new course using Collapsed topics format throws a "Error reading database" message.

It seems that course_get_students() function in classes/activity.php is using get_enrolled_users() function in Moodle core. It is trying to get all enrolled users from the current course. But when we are creating a new course the course ID is 1, so it fetches ALL users (from Moodle front page "course").

Debug info is very long and it shows the full database query (I removed the user id's on IN clause):

number of parameters must be between 0 and 65535. SELECT ra.*, r.name, r.shortname, ra.userid FROM mdl_role_assignments ra, mdl_role r, mdl_context c WHERE ra.userid IN (...) AND ra.roleid = r.id AND ra.contextid = c.id AND ra.contextid = XXXX ORDER BY c.contextlevel DESC, r.sortorder ASC

Stack trace: line 494 of /lib/dml/moodle_database.php: dml_read_exception thrown line 293 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end() line 341 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->read_slave_query_end() line 1027 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end() line 2970 of /lib/accesslib.php: call to pgsql_native_moodle_database->get_records_sql() line 692 of /course/format/topcoll/classes/activity.php: call to get_users_roles() line 740 of /course/format/topcoll/classes/activity.php: call to format_topcoll\activity::course_get_students() line 866 of /course/format/topcoll/lib.php: call to format_topcoll\activity::maxstudentsnotexceeded() line 947 of /course/format/classes/base.php: call to format_topcoll->course_format_options() line 1149 of /course/format/topcoll/lib.php: call to core_courseformat\base->create_edit_form_elements() line 443 of /course/edit_form.php: call to format_topcoll->create_edit_form_elements() line 1024 of /lib/formslib.php: call to course_edit_form->definition_after_data() line 250 of /course/edit.php: call to moodleform->display()

To Reproduce Steps to reproduce the behaviour:

  1. You need a Moodle instance with over 65535 users...
  2. Go to course default setting (Site administration > Courses > Course default settings) and select "Collapsed topics" as default course format.
  3. Go to a course category.
  4. Click on 'Add a new course'.
  5. See error.

Expected behaviour The new course settings form is displayed.

Versions:

gjb2048 commented 1 year ago

@anieminen I can understand how this can happen and envision a fix. However, I've always hated this code, so my inclination is to remove the additional functionality that the 'showadditionalmoddata' provides.