There is a bug in grade_object::fetch_all_helper() (/lib/grade/grade_object.php lines 162-72) such that when one of the values in the function argument $params is null, the values get out of sync with the sql query they relate to.
The code builds up two arrays (lines 162-72), one containing the new SQL_PARAMS_QM db syntax and the other containing the numerically indexed values. However because the second array is not empty when the loop begins these items are pushed onto the end of an existing array, meaning that they are not properly matched to their corresponding question mark.
In moodle_database::fix_sql_params() (/lib/dml/moodle_database.php line 711
) the $params argument is then array_sliced() to the correct length, cutting off the values that should have been passed in.
The result of this is that fetch_all_helper() will always return false for any index with a value of null in $params (or at least this is what happens in MySQL because the equals sign is not a null safe operator, different buggy behaviour may be exhibited in other db environments).
This is highly problematic as it means that public API functions with a dependency on fetch_all_helper() (like grade_update_outcomes(), which is how I found the bug) don't to work properly.