Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
anieminen opened this issue Oct 25, 2023 · 1 comment
Open

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

anieminen opened this issue Oct 25, 2023 · 1 comment
Assignees
Labels
Bug Triaged Issue read and is on backlog

Comments

@anieminen
Copy link

anieminen commented Oct 25, 2023

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:
0. You need a Moodle instance with over 65535 users...

  1. Go to course default setting (Site administration > Courses > Course default settings) and select "Collapsed topics" as default course format.
  2. Go to a course category.
  3. Click on 'Add a new course'.
  4. See error.

Expected behaviour
The new course settings form is displayed.

Versions:

  • Moodle: 4.1.6
  • Format: 401.1.1
  • Browser and version: All
@gjb2048 gjb2048 added the Triaged Issue read and is on backlog label Oct 25, 2023
@gjb2048
Copy link
Collaborator

gjb2048 commented Nov 11, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Triaged Issue read and is on backlog
Projects
None yet
Development

No branches or pull requests

2 participants