Problems with sga grade submission

Hi,
I have faced the same trouble (as Need information about persistent grades) and I have found some solutions but first at all, let me explain the problem, when sga creates a submission, some values are required, sga has a method called get_student_item_dict in order to get those values, the issue starts here with the value of ITEM_TYPE https://github.com/mitodl/edx-sga/blob/master/edx_sga/sga.py#L672, sga is storing all the submission with the value ‘sga’, look this file https://github.com/mitodl/edx-sga/blob/master/edx_sga/constants.py#L4, so the platform, when it is calculating the grades, does a similar thing https://github.com/edx/edx-platform/blob/master/lms/djangoapps/grades/tasks.py#L264, in this case the item value comes from the result of the line 214, same file , that is an object generated from a location string, for example, block-v1:edx+CS102+2019_T3+type@edx_sga+block@2acc79ce6d6b42199a93841ab408bee5, here the value of item_type will be ‘edx_sga’, hence when the platform looks for a submission with item_type= ‘edx_sga’, it will never found any submissions and will raise the exception of the file tasks.py line 234.

Now the possible solutions
This is not backwards compatible
Change the item_type in sga constants file to ‘edx_sga’, If you have some sga xblocks with submissions, this change will not show previous submissions and this will raise an exception or 500 error, since this will try to create a new submission with same student_id, item_ir and course_id, that is allowed once, so you should delete previous submissions from the database or delete previous sga components and create new ones.

Second approach

Change this line https://github.com/mitodl/edx-sga/blob/master/setup.py#L38 to ‘sga = edx_sga.sga:StaffGradedAssignmentXBlock’, this change will generate a location string like this block-v1:edx+CS102+2019_T3+type@sga+block@2acc79ce6d6b42199a93841ab408bee5, the previous sga blocks will disappear and you have to create new ones, and change in studio the advanced settings from ‘edx_sga’ to ‘sga’

Third approach, I reckon this is very ugly, however it works with previous sga components

it is to add a condition previous to this line https://github.com/edx/edx-platform/blob/master/lms/djangoapps/grades/tasks.py#L264, also you have to change the line 269
if scored_block_usage_key.block_type == ‘edx_sga’:
item_type = ‘sga’
else:
item_type = scored_block_usage_key.block_type

Please let me know your thoughts, maybe you have a better solution.

Thanks for this nice summary of the problem.

I think this is the best solution; it sounds like the SGA XBlock is using “item_type” incorrectly. Could this fix be done along with a one-time data migration that changes item_type from ‘sga’ to ‘edx_sga’ in the database?