File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed
tests/modeltests/model_forms Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ class FieldError(Exception):
33
33
pass
34
34
35
35
NON_FIELD_ERRORS = '__all__'
36
- class ValidationError (Exception ):
36
+ class BaseValidationError (Exception ):
37
37
"""An error while validating data."""
38
38
def __init__ (self , message , code = None , params = None ):
39
39
import operator
@@ -63,3 +63,11 @@ def __str__(self):
63
63
if hasattr (self , 'message_dict' ):
64
64
return repr (self .message_dict )
65
65
return repr (self .messages )
66
+
67
+ class ValidationError (BaseValidationError ):
68
+ pass
69
+
70
+ class UnresolvableValidationError (BaseValidationError ):
71
+ """Validation error that cannot be resolved by the user."""
72
+ pass
73
+
Original file line number Diff line number Diff line change 9
9
from django .utils .text import get_text_list , capfirst
10
10
from django .utils .translation import ugettext_lazy as _ , ugettext
11
11
12
- from django .core .exceptions import ValidationError , NON_FIELD_ERRORS
12
+ from django .core .exceptions import ValidationError , NON_FIELD_ERRORS , UnresolvableValidationError
13
13
from django .core .validators import EMPTY_VALUES
14
14
from util import ErrorList
15
15
from forms import BaseForm , get_declared_fields
@@ -254,10 +254,14 @@ def clean(self):
254
254
if k in self .cleaned_data :
255
255
del self .cleaned_data [k ]
256
256
257
- # what about fields that don't validate but aren't present on the form?
258
257
if NON_FIELD_ERRORS in e .message_dict :
259
258
raise ValidationError (e .message_dict [NON_FIELD_ERRORS ])
260
259
260
+ # there are errors on some fields not displayed in this form
261
+ if set (e .message_dict .keys ()) - set (self .fields .keys () + [NON_FIELD_ERRORS ]):
262
+ raise UnresolvableValidationError (e .message_dict )
263
+
264
+
261
265
return self .cleaned_data
262
266
263
267
def save (self , commit = True ):
Original file line number Diff line number Diff line change @@ -1432,9 +1432,9 @@ def __unicode__(self):
1432
1432
... exclude = ('quantity',)
1433
1433
>>> form = PriceForm({'price': '6.00'})
1434
1434
>>> form.is_valid()
1435
- False
1436
- >>> form.errors
1437
- {'quantity': [u'This field cannot be null.']}
1435
+ Traceback (most recent call last):
1436
+ ...
1437
+ UnresolvableValidationError: {'quantity': [u'This field cannot be null.']}
1438
1438
1439
1439
# Unique & unique together with null values
1440
1440
>>> class BookForm(ModelForm):
You can’t perform that action at this time.
0 commit comments