#27263: Allow validators to short-circuit in form field validation
---------------------------------+-----------------------------------------
     Reporter:  Alexey Rogachev  |                    Owner:  nobody
         Type:  New feature      |                   Status:  new
    Component:  Forms            |                  Version:  master
     Severity:  Normal           |               Resolution:
     Keywords:  form, validator  |             Triage Stage:  Someday/Maybe
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+-----------------------------------------

Comment (by Alexey Rogachev):

 The name of parameter (`show_circuit_validation`) is approximate, can be
 discussed and changed. I disagree that it covers specific use case. It's
 needed quite often, and in my opinion it's more logical than apply all
 validators one by one regardless of previous errors and should be default
 strategy. I'm not sure that creating a wrapper validator will be a good
 solution because validators in set can vary. Also this will require to
 change the way it's defined or subclass fields to override this logic,
 because this is defined in field.

 As a workaround I can just do a set of calls in form's `clean_import_file`
 method like that:

 def clean_import_file(self):
     import_file = self.cleaned_data.get('import_file')
     if import_file:
         FileSizeValidator(max_size='500 kb')(import_file)
         FileTypeValidator(extensions=('xlsx',))(import_file)
     return import_file

 But I don't like this approach, even code is DRY, validators is not a part
 of configuration anymore.

--
Ticket URL: <https://code.djangoproject.com/ticket/27263#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.aa098ec863e1f6c10950cb2cf1ce6886%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to