Skip to content

Commit 03a482a

Browse files
committed
fix: cast grading policy corretly as numbers (#273)
Fixes an issue with some courses causing the progress page to crash
1 parent ff88201 commit 03a482a

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lms/djangoapps/course_home_api/progress/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ def _build_policy_map(self) -> dict:
130130
policy_map = {}
131131
for policy in self.grading_policy.get('GRADER', []):
132132
policy_map[policy.get('type')] = {
133-
'weight': policy.get('weight', 0.0),
133+
'weight': float(policy.get('weight', 0.0) or 0.0),
134134
'short_label': policy.get('short_label', ''),
135-
'num_droppable': policy.get('drop_count', 0),
136-
'num_total': policy.get('min_count', 0),
135+
'num_droppable': int(policy.get('drop_count', 0) or 0),
136+
'num_total': int(policy.get('min_count', 0) or 0),
137137
}
138138
return policy_map
139139

lms/djangoapps/course_home_api/progress/tests/test_api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ def _make_subsection(fmt, earned, possible, show_corr, *, due_delta_days=None, i
8787
],
8888
{'avg': 0.0, 'weighted': 0.0, 'hidden': 'all', 'final': 0.0, 'last_grade_publish_date_days': 7},
8989
),
90+
(
91+
'string_typed_policy_counts',
92+
{'type': 'Homework', 'weight': '1.0', 'drop_count': '1', 'min_count': '2', 'short_label': 'HW'},
93+
[
94+
_make_subsection('Homework', 1, 1, ShowCorrectness.ALWAYS),
95+
_make_subsection('Homework', 0, 1, ShowCorrectness.ALWAYS),
96+
],
97+
{'avg': 1.0, 'weighted': 1.0, 'hidden': 'none', 'final': 1.0},
98+
),
9099
]
91100

92101

@@ -187,7 +196,7 @@ def test_aggregate_assignment_type_grade_summary_scenarios(self):
187196
assert row['average_grade'] == expected['avg']
188197
assert row['weighted_grade'] == expected['weighted']
189198
assert row['has_hidden_contribution'] == expected['hidden']
190-
assert row['num_droppable'] == policy['drop_count']
199+
assert row['num_droppable'] == int(policy['drop_count'])
191200
assert (row['last_grade_publish_date'] is not None) == (
192201
'last_grade_publish_date_days' in expected
193202
)

0 commit comments

Comments
 (0)