Commit d1312d97db3c1c68be7919a7a6b656f59a1d9786

Authored by Rohan Rangray
1 parent 1c22f48d88
Exists in master

Added better error checking in QuizRequestSerializer.validate_sections

Showing 1 changed file with 4 additions and 1 deletions Side-by-side Diff

flashcards/serializers.py View file @ d1312d9
... ... @@ -10,6 +10,7 @@
10 10 from rest_framework.serializers import ModelSerializer, Serializer, PrimaryKeyRelatedField, ListField
11 11 from rest_framework.validators import UniqueValidator
12 12 from flashy.settings import QUARTER_END, QUARTER_START
  13 +from collections import Iterable
13 14  
14 15  
15 16 class EmailSerializer(Serializer):
... ... @@ -201,7 +202,9 @@
201 202 raise serializers.ValidationError("Invalid end date for the flashcard range")
202 203  
203 204 def validate_sections(self, value):
204   - if value is None:
  205 + if value is not None and not isinstance(value, Iterable):
  206 + raise serializers.ValidationError("Invalid section format. Expecting a list or no value.")
  207 + if value is None or len(value) == 0:
205 208 return Section.objects.all()
206 209 section_filter = Section.objects.filter(pk__in=value)
207 210 if not section_filter.exists():