File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
django_mongodb_backend/forms/fields Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 2
2
from itertools import chain
3
3
4
4
from django import forms
5
- from django .core .exceptions import ValidationError
5
+ from django .core .exceptions import ImproperlyConfigured , ValidationError
6
6
from django .utils .translation import gettext_lazy as _
7
7
8
8
from ...utils import prefix_validation_error
@@ -20,6 +20,11 @@ def __init__(
20
20
self .base_field = base_field
21
21
self .delimiter = delimiter
22
22
super ().__init__ (** kwargs )
23
+ if (min_length is not None or max_length is not None ) and size is not None :
24
+ raise ImproperlyConfigured (
25
+ "SimpleArrayField param 'size' cannot be "
26
+ "specified with 'max_length' or 'min_length'."
27
+ )
23
28
if min_length is not None :
24
29
self .min_length = min_length
25
30
self .validators .append (ArrayMinLengthValidator (int (min_length )))
Original file line number Diff line number Diff line change @@ -145,6 +145,15 @@ def test_required(self):
145
145
field .clean ("" )
146
146
self .assertEqual (cm .exception .messages [0 ], "This field is required." )
147
147
148
+ def test_misconfigured (self ):
149
+ msg = "SimpleArrayField param 'size' cannot be specified with 'max_length' or 'min_length'."
150
+ with self .assertRaises (exceptions .ImproperlyConfigured ) as cm :
151
+ SimpleArrayField (forms .CharField (), max_length = 3 , size = 2 )
152
+ self .assertEqual (cm .exception .args [0 ], msg )
153
+ with self .assertRaises (exceptions .ImproperlyConfigured ) as cm :
154
+ SimpleArrayField (forms .CharField (), min_length = 3 , size = 2 )
155
+ self .assertEqual (cm .exception .args [0 ], msg )
156
+
148
157
def test_model_field_formfield (self ):
149
158
model_field = ArrayField (models .CharField (max_length = 27 ))
150
159
form_field = model_field .formfield ()
You can’t perform that action at this time.
0 commit comments