Trouble accessing message_dict of ValidationError

32 views
Skip to first unread message

Rosemary McCloskey

unread,
Aug 1, 2014, 11:33:18 AM8/1/14
to django...@googlegroups.com
Hi,

I'm writing a view to create a model, and am trying to capture any ValidationErrors and display them to the user. I have code that looks like this:

  # exceptions is a dict of errors already encountered
  try:
    # create model
  except ValidationError as e:
    for key, msg in e.message_dict.items():                                                            
      exceptions.update({key: str(msg[0])}) 

I'm getting the following error:

  Traceback (most recent call last):
    File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 114, in get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/home/rmcclosk/Documents/Shipyard/shipyard/method/views.py", line 529, in method_revise
      for key, msg in e.message_dict.items():
    File "/usr/local/lib/python2.7/dist-packages/django/core/exceptions.py", line 96, in message_dict
      for field, messages in self.error_dict.items():
  AttributeError: 'ValidationError' object has no attribute 'error_dict'

This looks like a Django bug to me, but I googled around and couldn't find anything similar. The same error also happens if I just try to print(e.message_dict) instead of iterating through it, it seems like just accessing message_dict is causing the problem. Any ideas about what could be wrong?

Thanks!
Reply all
Reply to author
Forward
0 new messages