kelvinwong-ca / django-select-multiple-field

Select multiple choices in a single Django model field
Other
34 stars 25 forks source link

Errors on empty fields #11

Open rasca opened 8 years ago

rasca commented 8 years ago

When having a blank=True, null=True SelectMultipleField and validating the field with an empty value it raises an Exception:

Traceback (most recent call last):
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
    return self.application(environ, start_response)
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
    response = self.get_response(request)
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/core/handlers/base.py", line 218, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/views/generic/base.py", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/ivan/Sites/hdmd/hdmd/medical_record/views.py", line 111, in dispatch
    return super(ProcessFormSetsView, self).dispatch(request, *args, **kwargs)
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/views/generic/base.py", line 89, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/ivan/Sites/hdmd/hdmd/medical_record/views.py", line 144, in post
    if form.is_valid():
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/forms/forms.py", line 184, in is_valid
    return self.is_bound and not self.errors
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/forms/forms.py", line 176, in errors
    self.full_clean()
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/forms/forms.py", line 392, in full_clean
    self._clean_fields()
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/forms/forms.py", line 407, in _clean_fields
    value = field.clean(value)
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/forms/fields.py", line 163, in clean
    self.validate(value)
  File "/home/ivan/.virtualenvs/hdmd/lib/python2.7/site-packages/django/forms/fields.py", line 937, in validate
    for val in value:
TypeError: 'NoneType' object is not iterable