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

Exception - count(): Argument #1 ($value) must be of type Countable|array, null given #15

Open
Richardvi opened this issue Jan 8, 2024 · 8 comments

Comments

@Richardvi
Copy link

Describe the bug
A clear and concise description of what the bug is. We are using Moodle 4.3.2

When clicking on the Rubric Breakdown Report the following error occurs: Exception - count(): Argument #1 ($value) must be of type Countable|array, null given

To Reproduce
Screenshots

Our Rubric looks like this:

image

@marcusgreen
Copy link
Owner

Thanks Richard, any chance you can give me access to a course where this happens?

@Richardvi
Copy link
Author

That is kinda difficult to realize as we do not create accounts in our own Moodle, everyone logs in using ADFS.

What I could do is create a backup from this specific assignment and send it to you? Would that help?

Also, we are using multiple attempts in assignments. Could that be a problem in the report?

@marcusgreen
Copy link
Owner

Yes a backup/restore would probably help and yes multiple attempts might be an issue (though I have a vague recollection of testing against that).
This report does a similar thing and it would be interesting to know if it runs without error on your site..
https://github.com/brickfield/moodle-gradereport_rubrics

@CristhianBohorquez
Copy link

Error message

Exception - count(): Argument #1 ($value) must be of type Countable|array, null given

More information about this error

Debug info:
Error code: generalexceptionmessage×Dismiss this notification
Stack trace:
line 54 of /report/advancedgrading/guide.php: TypeError thrown
×Dismiss this notification
Output buffer:

Error: mdb->get_record() found more than one record!
  • line 1691 of /lib/dml/moodle_database.php: call to debugging()
  • line 50 of /report/advancedgrading/locallib.php: call to moodle_database->get_record_sql()
  • line 178 of /report/advancedgrading/locallib.php: call to get_grading_definition()
  • line 39 of /report/advancedgrading/guide.php: call to init()
Invalid get_string() identifier: 'pluginname' or component 'gradingform_'. Perhaps you are missing $string['pluginname'] = ''; in /lang/en/gradingform_.php?
  • line 356 of /lib/classes/string_manager_standard.php: call to debugging()
  • line 7414 of /lib/moodlelib.php: call to core_string_manager_standard->get_string()
  • line 99 of /report/advancedgrading/locallib.php: call to get_string()
  • line 186 of /report/advancedgrading/locallib.php: call to header_fields()
  • line 39 of /report/advancedgrading/guide.php: call to init()
Error: mdb->get_record() found more than one record!
  • line 1691 of /lib/dml/moodle_database.php: call to debugging()
  • line 50 of /report/advancedgrading/locallib.php: call to moodle_database->get_record_sql()
  • line 187 of /report/advancedgrading/locallib.php: call to get_grading_definition()
  • line 39 of /report/advancedgrading/guide.php: call to init()

Looking into the plugin function
https://github.com/marcusgreen/moodle-report_advancedgrading/blob/main/locallib.php#L41

/**

  • Get the structure of this grading definition
  • @param int $assignid
  • @return \stdClass
    */
    function get_grading_definition(int $assignid): \stdClass {
    global $DB;
    $sql = "SELECT gdef.id AS definitionid, ga.activemethod, gdef.name AS definition
    FROM {assign} assign
    JOIN {course_modules} cm ON cm.instance = assign.id
    JOIN {context} ctx ON ctx.instanceid = cm.id
    JOIN {grading_areas} ga ON ctx.id=ga.contextid
    JOIN {grading_definitions} gdef ON ga.id = gdef.areaid
    WHERE assign.id = :assignid";
    $definition = $DB->get_record_sql($sql, ['assignid' => $assignid]);
    return $definition;
    }

The current query has the potential to join to unrelated course module or context records, that is why it is happening the error.

$sql = "SELECT gdef.id AS definitionid, ga.activemethod, gdef.name AS definition
FROM {assign} assign
JOIN {course_modules} cm ON cm.instance = assign.id
JOIN {modules} m ON m.id = cm.module AND m.name = 'assign'
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = 70
JOIN {grading_areas} ga ON ctx.id=ga.contextid
JOIN {grading_definitions} gdef ON ga.id = gdef.areaid
WHERE assign.id = :assignid"

@marcusgreen
Copy link
Owner

marcusgreen commented Apr 28, 2024

I will investigate

@Richardvi
Copy link
Author

Richardvi commented Apr 28, 2024

I still had this on my to do list, but unfortunately I was unable to share the backup as there's personalized data inside the course.

So thanks to @CristhianBohorquez for sharing additional info.

I think the trouble is the many 0 points in the rubric.

@mikehenry1979-bah
Copy link

Had this same exception, the query above was returning two grade_definitions rows for one assignment ID, and upon examination one row had a mismatch between gdef.method and ga.activemethod. Therefore the next part of code was loading from the wrong mdl_gradingform_x_criteria table (x = guide or rubric) and not populating $data['criteria'], causing the count() null exception on the rubric.php page. What fixed it here was to add an AND onto the last join, JOIN {grading_definitions} gdef ON ga.id = gdef.areaid AND gdef.method = ga.activemethod.

@mikehenry1979-bah
Copy link

Alternatively, after I removed my patch and the error came back, a site admin was able to fix the error by deleting the grading guide from the assignment and ensuring that the assignment and advanced grading settings were both set to rubric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants