Commit fb0442a7 by Justin Riley

attempt_stats: fix TypeError when loading SM states

StudentModule.state is allowed to be None (null=True, blank=True) so
json.loads calls have to provide a default in this case (e.g. '{}').
parent 3aa01744
...@@ -55,7 +55,7 @@ def passed(state): ...@@ -55,7 +55,7 @@ def passed(state):
def update_stats(sm, stat, history=False): def update_stats(sm, stat, history=False):
if sm.grade is None: if sm.grade is None:
return return
state = json.loads(sm.state) state = json.loads(sm.state or '{}')
if 'attempts' not in state: if 'attempts' not in state:
return return
if not state.get('done', False): if not state.get('done', False):
...@@ -95,7 +95,7 @@ def compute_stats(course_id): ...@@ -95,7 +95,7 @@ def compute_stats(course_id):
if ret in ['passed', 'attempted']: if ret in ['passed', 'attempted']:
continue continue
smhset = StudentModuleHistory.objects.filter(student_module=sm) smhset = StudentModuleHistory.objects.filter(student_module=sm)
states = [json.loads(smh.state) for smh in smhset] states = [json.loads(smh.state or '{}') for smh in smhset]
okset = [passed(x) for x in states] okset = [passed(x) for x in states]
attempts = [x.get('attempts', 0) for x in states] attempts = [x.get('attempts', 0) for x in states]
stat.nattempts += max(attempts) stat.nattempts += max(attempts)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment