vtos / moodle-mod_adaptivequiz

CAT (Computer-Adaptive Testing) implementation for Moodle LMS (https://moodle.org): officially supported plugin.
https://moodle.org/plugins/mod_adaptivequiz
5 stars 9 forks source link

If no questions are attempted: Duplicate value '0' found in column 'uniqueid' #20

Closed davidszkiba closed 1 year ago

davidszkiba commented 1 year ago

@vtos Hi Vitaly!

I'm implementing a catmodel subplugin according to your latest changes and it's working great so far, but I came across an issue. In this subplugin, it can happen that not a single question is applicable. In such a case, the quiz attempt stops without any question being shown to the user. However, when such empty attempts happen more than once, I get an error about duplicate values in the database when the attempt is finished:

Did you remember to make the first column something unique in your call to get_records? Duplicate value '0' found in column 'uniqueid'.

    line 1039 of /lib/dml/pgsql_native_moodle_database.php: call to debugging()
    line 256 of /mod/adaptivequiz/locallib.php: call to pgsql_native_moodle_database->get_records_sql()
    line 706 of /mod/adaptivequiz/lib.php: call to adaptivequiz_get_user_grades()
    line 148 of /mod/adaptivequiz/classes/local/attempt/attempt.php: call to adaptivequiz_update_grades()
    line 111 of /mod/adaptivequiz/classes/local/adaptive_quiz_session.php: call to mod_adaptivequiz\local\attempt\attempt->complete()
    line 141 of /mod/adaptivequiz/attempt.php: call to mod_adaptivequiz\local\adaptive_quiz_session->administer_next_item_or_stop()

I think the reason is as follows: If I return a stoppage reason in my item_administration immediately, even before a single question is returned, there will be an entry in the adaptivequiz_attempt database table with a uniqueid of 0. If I repeat this in another attempt, a second entry with a uniqueid of 0 will be stored in the database.

Do you plan to update the code so that "empty attempts" are possible or do you have any suggestion how I can get rid of this error?

Thanks

vtos commented 1 year ago

@davidszkiba Hi David,

This requires some in-depth look, I'll look into what's happening there closely, thanks for the details.

vtos commented 1 year ago

@davidszkiba the changes have been pushed to both catmodel_subplugins branches, the error should not be apeearing any more.