Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #13107: Adjusted decimal_places validation to accept 0 as a val…

…id value. Thanks to loewis for report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12774 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c10b227b6961dc4420d991fd4d90276499000e5c 1 parent 794690c
Karen Tracey authored March 13, 2010
12  django/core/management/validation.py
@@ -45,18 +45,20 @@ def get_validation_errors(outfile, app=None):
45 45
                 except (ValueError, TypeError):
46 46
                     e.add(opts, '"%s": CharFields require a "max_length" attribute that is a positive integer.' % f.name)
47 47
             if isinstance(f, models.DecimalField):
  48
+                decimalp_msg ='"%s": DecimalFields require a "decimal_places" attribute that is a non-negative integer.'
48 49
                 try:
49 50
                     decimal_places = int(f.decimal_places)
50  
-                    if decimal_places <= 0:
51  
-                        e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute that is a positive integer.' % f.name)
  51
+                    if decimal_places < 0:
  52
+                        e.add(opts, decimalp_msg % f.name)
52 53
                 except (ValueError, TypeError):
53  
-                    e.add(opts, '"%s": DecimalFields require a "decimal_places" attribute that is a positive integer.' % f.name)
  54
+                    e.add(opts, decimalp_msg % f.name)
  55
+                mdigits_msg = '"%s": DecimalFields require a "max_digits" attribute that is a positive integer.'
54 56
                 try:
55 57
                     max_digits = int(f.max_digits)
56 58
                     if max_digits <= 0:
57  
-                        e.add(opts, '"%s": DecimalFields require a "max_digits" attribute that is a positive integer.' % f.name)
  59
+                        e.add(opts,  mdigits_msg % f.name)
58 60
                 except (ValueError, TypeError):
59  
-                    e.add(opts, '"%s": DecimalFields require a "max_digits" attribute that is a positive integer.' % f.name)
  61
+                    e.add(opts, mdigits_msg % f.name)
60 62
             if isinstance(f, models.FileField) and not f.upload_to:
61 63
                 e.add(opts, '"%s": FileFields require an "upload_to" attribute.' % f.name)
62 64
             if isinstance(f, models.ImageField):
6  tests/modeltests/invalid_models/models.py
@@ -210,11 +210,11 @@ class UniqueFKTarget2(models.Model):
210 210
 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer.
211 211
 invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer.
212 212
 invalid_models.fielderrors: "charfield3": CharFields require a "max_length" attribute that is a positive integer.
213  
-invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute that is a positive integer.
  213
+invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute that is a non-negative integer.
214 214
 invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute that is a positive integer.
215  
-invalid_models.fielderrors: "decimalfield2": DecimalFields require a "decimal_places" attribute that is a positive integer.
  215
+invalid_models.fielderrors: "decimalfield2": DecimalFields require a "decimal_places" attribute that is a non-negative integer.
216 216
 invalid_models.fielderrors: "decimalfield2": DecimalFields require a "max_digits" attribute that is a positive integer.
217  
-invalid_models.fielderrors: "decimalfield3": DecimalFields require a "decimal_places" attribute that is a positive integer.
  217
+invalid_models.fielderrors: "decimalfield3": DecimalFields require a "decimal_places" attribute that is a non-negative integer.
218 218
 invalid_models.fielderrors: "decimalfield3": DecimalFields require a "max_digits" attribute that is a positive integer.
219 219
 invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute.
220 220
 invalid_models.fielderrors: "choices": "choices" should be iterable (e.g., a tuple or list).

0 notes on commit c10b227

Please sign in to comment.
Something went wrong with that request. Please try again.