SQL multiple records in submission table and Grade = -1

SQL multiple records in submission table and Grade = -1

by Howard Miller -
Number of replies: 3
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Moodle 3.1.3. This is a bit vague, but I'm hoping someone might have seen this before so please bear with me. 

The complaint was that in a group submission assignment, some teachers could see a student as marked and for other teachers the same student was not marked (for multiple students). With debugging on, sure enough, multiple instances of...

Did you remember to make the first column something unique in your call to get_records? Duplicate value '24597' found in column 'id'.
  • line 1097 of /lib/dml/mysqli_native_moodle_database.php: call to debugging()
  • line 1593 of /lib/tablelib.php: call to mysqli_native_moodle_database->get_records_sql()
  • line 1614 of /lib/tablelib.php: call to table_sql->query_db()
  • line 1439 of /mod/assign/renderer.php: call to table_sql->out()
  • line 1235 of /mod/assign/renderer.php: call to mod_assign_renderer->flexible_table()
  • line 319 of /lib/outputrenderers.php: call to mod_assign_renderer->render_assign_grading_table()
  • line 3795 of /mod/assign/locallib.php: call to plugin_renderer_base->render()
  • line 3869 of /mod/assign/locallib.php: call to assign->view_grading_table()
  • line 572 of /mod/assign/locallib.php: call to assign->view_grading_page()
  • line 52 of /mod/assign/view.php: call to assign->view()

With a minimum of digging, this was talking about this bit of SQL..

SELECT
                u.id,u.picture,u.firstname,u.lastname,u.firstnamephonetic,u.lastnamephonetic,u.middlename,u.alternatename,u.imagealt,u.email, u.id as userid, s.status as status, s.id as submissionid, s.timecreated as firstsubmission, s.timemodified as timesubmitted, s.attemptnumber as attemptnumber, g.id as gradeid, g.grade as grade, g.timemodified as timemarked, g.timecreated as firstmarked, uf.mailed as mailed, uf.locked as locked, uf.extensionduedate as extensionduedate, uf.workflowstate as workflowstate, uf.allocatedmarker as allocatedmarker , um.id as recordid 
                FROM {user} u
                         LEFT JOIN {assign_submission} s
                                ON u.id = s.userid
                               AND s.assignment = :assignmentid1
                               AND s.latest = 1
                         LEFT JOIN {assign_grades} g
                                ON u.id = g.userid
                               AND g.assignment = :assignmentid2 LEFT JOIN (SELECT mxg.userid, MAX(mxg.attemptnumber) AS maxattempt
                                  FROM {assign_grades} mxg
                                 WHERE mxg.assignment = :assignmentid4
                              GROUP BY mxg.userid) gmx
                             ON u.id = gmx.userid
                            AND g.attemptnumber = gmx.maxattempt LEFT JOIN {assign_user_flags} uf
                         ON u.id = uf.userid
                        AND uf.assignment = :assignmentid3 LEFT JOIN {assign_user_mapping} um
                             ON u.id = um.userid
                            AND um.assignment = :assignmentid5 
                WHERE u.id IN (:user17,:user18,:user19,:user20,:user21)
                ORDER BY userid ASC

Having substituted some parameters (for a single submission group) on my dev site, and run the query this is returned (select cut down a lot for clarity)...

+-----+--------+--------------+---------------+---------+----------+----------+
| id  | userid | submissionid | attemptnumber | gradeid | grade    | recordid |
+-----+--------+--------------+---------------+---------+----------+----------+
| 709 |    709 |         2202 |             5 |    1269 | 56.66667 |       96 |
| 709 |    709 |         2202 |             5 |    1270 | -1.00000 |       96 |
| 709 |    709 |         2202 |             5 |    1271 | -1.00000 |       96 |
| 709 |    709 |         2202 |             5 |    1272 | -1.00000 |       96 |
| 709 |    709 |         2202 |             5 |    1273 | -1.00000 |       96 |
| 709 |    709 |         2202 |             5 |    1274 | -1.00000 |       96 |
| 716 |    716 |         2214 |             5 |    1280 | -1.00000 |       22 |
| 716 |    716 |         2214 |             5 |    1281 | 56.66667 |       22 |
| 716 |    716 |         2214 |             5 |    1282 | -1.00000 |       22 |
| 726 |    726 |         2229 |             5 |    1288 | -1.00000 |       28 |
| 726 |    726 |         2229 |             5 |    1289 | 56.66667 |       28 |
| 726 |    726 |         2229 |             5 |    1290 | -1.00000 |       28 |
| 746 |    746 |         2256 |             5 |    1302 | 56.66667 |       71 |
| 770 |    770 |         2285 |             5 |    1318 | 56.66667 |       60 |
+-----+--------+--------------+---------------+---------+----------+----------+

So, it is indeed pulling multiple results for some students. The problem appears to be caused by the record 'Grade = -1'. I have no idea what that means or is doing in the data...

Any thoughts?


Average of ratings: Useful (1)
In reply to Howard Miller

Re: SQL multiple records in submission table and Grade = -1

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

This looks very similar to MDL-57511, which affected the quiz.

In reply to Tim Hunt

Re: SQL multiple records in submission table and Grade = -1

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It does...

Although we have yet to reproduce it, we *think* this is possibly related to teachers moving students around in groups after they have submitted to this group assignment. In many ways that doesn't make a lot of sense but it shouldn't break it. It didn't in testing (of course). 

I'm not sure when Assignment creates these Gradebook entries.

Average of ratings: Useful (1)
In reply to Howard Miller

Re: SQL multiple records in submission table and Grade = -1

by Niklas Frost -

Hi! I have the same error message on a course (maybe 2) Moodle 3.2.4 (Build: 20170710), dealing with <20 students being in several groups and 1 grouping connected to the assignments. 

We use cohort import of students, not manual.

The teachers complain on arbitrary and wrong Moodle views regarding student grades on 2 different assignments.

Most of the time it works correctly.  But...sometimes some student that are graded OK - are flunked by Moodle, sometimes 1 student in a group assignment pass but his fellow student in the same group flunks. They are graded differently by Moodle.

And yes.. the problem is the -1.0000 grade ghost. Confirmed in db. It maps 100% on the double records and the faulty student gradings behavior.

I see many possible reasons for this behavior:
A) It is possible course secretary/managers/teachers moved students around in groups at some point. Any hint/tip what logs/reports to search in would be appreciated!

The groups are picked by moodle from the grouping dedicated to the assignment

They use group assignments to make it ever more complex...

IF they moved people around between groups after assignment submissions started, I sure do not know how any Moodle programmer or code would have solved that logically. Yet there are now warnings or blocking rules.

The only logical strategy for the Moodle would(?) be to make it not possible to move people in groups if groups are connected to  assignment/and or group  submissions. Compare scale edit rules. Then again - I understand - that would probably be a showstopper for something else..

B)    The way they created scales & rubrics in the assignment. They might very well ended up with a very  creative and error prone wrongful mix of assignment/scale/rubric/grade configs that somehow made it thru. I am checking that now.

C) I tried to see why certain students grades works fine  and some do not. In vain so far. To be continued.


Best regards, Niklas

And Merry X-mas smile