Hi,

I'm upgrading to Django 1.7, and updating my forms to use the new form.add_errors() method.

I have one remaining pattern which uses form._errors.

class MyForm(forms.Form):
    ...
    def clean():
       cleaned_data = super(MyForm, self).clean()
       if not self._errors:
           do_something()

I only want to call do_something() if no errors have been found during the validation so far. I'd rather not use self._errors, since it is now a private API according to the release notes [1]. What's the recommended way to replace self._errors here?

Is it ok to use self.errors instead? Looking at the source code [2], errors is a property, not an attribute. By the time the clean() method is called, self._errors should have been created, so I think that accessing self.errors should be safe.

cheers,
Alasdair

[1]: https://docs.djangoproject.com/en/dev/releases/1.7/#form-add-error
[2]: https://github.com/django/django/blob/1.7.1/django/forms/forms.py#L150

--
Alasdair Nicol
Developer, MEMSET

mail: alasd...@memset.com
 web: http://www.memset.com/

Memset Ltd., registration number 4504980.
Building 87, Dunsfold Park, Stovolds Hill, Cranleigh, Surrey, GU6 8TB, UK

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5465E3AC.2040804%40memset.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to