https://docs.djangoproject.com/en/dev/ref/forms/validation/ (see first paragraph)
def is_valid(self):
"""Returns True if the form has no errors. Otherwise, False. If errors arebeing ignored, returns False."""return self.is_bound and not bool(self.errors)
https://code.djangoproject.com/browser/django/trunk/django/forms/forms.py
When it checks for self.errors, the _get_errors() function calls the full_clean.
Yeah, it's non-obvious. That's one of the nice things about
open-source, though. You can go through the code and understand how
your tools work so you can better apply them.
Side-note -- now that you're browsing Django's code, I think you could
easily participate by going to the Trac instance and closing a few
easy tickets. ;o) https://code.djangoproject.com/
Shawn
> I am puzzled by what I am see though with the BaseForm class in Aptana
> PyDev debugger. I noticed that full_clean() was not being called via a
> call to is_valid. So I stepped through the debugger, and for some
> strange reason, the BaseForm constructor, although the code says
> "self._errors = None" the debugger watchlist shows self._errors as set
> to an empty ErrorDict, and therefore the _get_errors() method never
> called full_clean().
>
> Does this make any sense? It doesn't sound right.
>
I haven't dug into this particular code, so I don't know why it works
that way. In any case, what is it that you're actually trying to
accomplish? I ask because I'm pretty sure Django form validation isn't
buggy or we'd know by now. If you're just trying to understand Django
then that's awesome, and I hope you figure it out or someone helps
out. But if you're digging into it to try to solve a problem in your
own code, what is it?
Shawn
Whether or not a form's values are valid has nothing to do with
whether the values are meaningful. That is, a login form with a
present but incorrect password is in fact valid.
I'm sure that full_clean is getting called, and the default value of
None is getting replaced by an empty ErrorDict once the clean
determines that no fields are invalid.
If you look at the code that's used by the django.contrib.auth to log
users in, there are more steps after simple form validation needed to
log a user in.
https://docs.djangoproject.com/en/1.3/topics/auth/#authentication-in-web-requests
After the form is validated, the values are then used with the
authenticate method to attempt to find a matching user in the
database. If one is found, an additional step is taken to update the
request with the user.
Understanding that, plus checking out the link above should clear up
your confusion. If you read and understand it but still think your
code has a different problem, please describe it in more detail.
Shawn
form = AuthenticationForm(request.POST)Instead of the correct way:
form = AuthenticationForm(request, data=request.POST)