TNL-3316: Error on Insights performance report

Preserve DRF v2 behavior of defaulting to None
for missing keys in the grading policy dictionary.
This commit is contained in:
Will Daly
2015-09-18 10:40:53 -07:00
committed by Brian Beggs
parent d11ccad0fc
commit 322db6de7a
2 changed files with 82 additions and 16 deletions

View File

@@ -1,6 +1,8 @@
"""
API Serializers
"""
from collections import defaultdict
from rest_framework import serializers
@@ -11,6 +13,19 @@ class GradingPolicySerializer(serializers.Serializer):
dropped = serializers.IntegerField(source='drop_count')
weight = serializers.FloatField()
def to_representation(self, obj):
"""
Return a representation of the grading policy.
"""
# Backwards compatibility with the behavior of DRF v2.
# When the grader dictionary was missing keys, DRF v2 would default to None;
# DRF v3 unhelpfully raises an exception.
return dict(
super(GradingPolicySerializer, self).to_representation(
defaultdict(lambda: None, obj)
)
)
# pylint: disable=invalid-name
class BlockSerializer(serializers.Serializer):