Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.1.X] Fixed #13107: Adjusted decimal_places validation to accept 0 …

…as a valid value. Thanks to loewis for report.

r12774 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@12775 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c94de0757097061753578c72fb2abc8a5c603531 1 parent e969c27
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
@@ -189,11 +189,11 @@ class UniqueM2M(models.Model):
189 189
 model_errors = """invalid_models.fielderrors: "charfield": CharFields require a "max_length" attribute that is a positive integer.
190 190
 invalid_models.fielderrors: "charfield2": CharFields require a "max_length" attribute that is a positive integer.
191 191
 invalid_models.fielderrors: "charfield3": CharFields require a "max_length" attribute that is a positive integer.
192  
-invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute that is a positive integer.
  192
+invalid_models.fielderrors: "decimalfield": DecimalFields require a "decimal_places" attribute that is a non-negative integer.
193 193
 invalid_models.fielderrors: "decimalfield": DecimalFields require a "max_digits" attribute that is a positive integer.
194  
-invalid_models.fielderrors: "decimalfield2": DecimalFields require a "decimal_places" attribute that is a positive integer.
  194
+invalid_models.fielderrors: "decimalfield2": DecimalFields require a "decimal_places" attribute that is a non-negative integer.
195 195
 invalid_models.fielderrors: "decimalfield2": DecimalFields require a "max_digits" attribute that is a positive integer.
196  
-invalid_models.fielderrors: "decimalfield3": DecimalFields require a "decimal_places" attribute that is a positive integer.
  196
+invalid_models.fielderrors: "decimalfield3": DecimalFields require a "decimal_places" attribute that is a non-negative integer.
197 197
 invalid_models.fielderrors: "decimalfield3": DecimalFields require a "max_digits" attribute that is a positive integer.
198 198
 invalid_models.fielderrors: "filefield": FileFields require an "upload_to" attribute.
199 199
 invalid_models.fielderrors: "choices": "choices" should be iterable (e.g., a tuple or list).

0 notes on commit c94de07

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