Don't allow empty lists when they are required

When using ListField, an empty list is added as the default value.
But when you mark this field as required, you expect it not to be empty,
so this patch makes sure that this is duly checked.
This commit is contained in:
Pau Aliagas 2011-10-03 16:42:10 +02:00
parent 60b6ad3fcf
commit d99c7c20cc

View File

@ -476,6 +476,10 @@ class ListField(ComplexBaseField):
isinstance(value, basestring)):
raise ValidationError('Only lists and tuples may be used in a '
'list field')
# don't allow empty lists when they are required
if self.required and not value:
raise ValidationError('Field "%s" is required and cannot be empty' %
self.name)
super(ListField, self).validate(value)
def prepare_query_value(self, op, value):