On May 23, 1:40 am, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
> On May 23, 5:07 am, Rex <rex.eastbou...@gmail.com> wrote:
> > On May 22, 4:33 pm, "R. Gorman" <r.m.gor...@gmail.com> wrote:
> > > On May 21, 10:48 pm, Rex <rex.eastbou...@gmail.com> wrote:
>
> > > > I have the following code in a view, where UserSurveyForm is a
> > > > ModelForm.
>
> > > > f = UserSurveyForm(request.POST, instance=thisuser)
> > > > if f.is_valid():
> > > >     [...]
>
> > > > When I try submitting valid data, this works fine. However, when I
> > > > submit an incomplete form, I get the following traceback:
>
> > > > [...]
> > > >   50.         if f.is_valid():
> > > > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
> > > >   319.         return save_instance(self, self.instance,
> > > > self._meta.fields, fail_message, commit)
> > > > File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> > > > save_instance
> > > >   42.                          " validate." % (opts.object_name,
> > > > fail_message))
>
> > > > Exception Type: ValueError at /games/pd/survey/
> > > > Exception Value: The User could not be changed because the data didn't
> > > > validate.
>
> > > > Based on the documentation I've read, I thought that is_valid() should
> > > > just return False if the form doesn't validate, instead of throwing an
> > > > error. Any information on this?
>
> > > > Thanks!
>
> > Thanks for the reply. It is that very "f.is_valid()" line that causes
> > the error, as indicated by the stack trace. (The next line is an
> > HttpResponse("foo").)
>
> > Is the above stack trace expected? The is_valid method appears cause
> > save() to be called. Is the issue (1) that save() isn't supposed to
> > throw a ValueError, or (2) that save() should not be called in the
> > first place?
>
> is_valid() should definitely not cause save() to be called. Can you
> post the code of your form? Maybe you have something weird in one of
> the clean methods.
> --
> DR.

I tried debugging the line "if f.is_valid():" a little more. It turns
out that the problem was not caused by the is_valid() method; it was
caused by evaluating the UserSurveyForm instance f (although I'm not
sure why). I didn't make any changes to my code. Instead, I deleted
and re-created the table corresponding to the User model (on which
UserSurveyForm was based), and now everything works correctly.

Thanks for all the valuable help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to