On May 22, 4:33 pm, "R. Gorman" <r.m.gor...@gmail.com> wrote: > You are correct in your understand that .is_valid() returns False if > the data is invalid. Are you sure you are not processing data > irrespective of whether the data validated or not? A little more > detail on how your processing your data might provide some insight. > > R. > > 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? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---