Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#5232 closed (fixed)

DecimalField max_digits counts negative sign as a digit.

Reported by: Andrew Durdin <adurdin@…> Owned by: adrian
Component: Validators Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


In [5680], the validation of decimal values for DecimalField was changed to fix #4807, which also introduced a bug in validating negative decimals, in that it counts the - sign as one of the digits:

>>> import django.core.validators
>>> v = django.core.validators.IsValidDecimal(max_digits=5, decimal_places=2)
>>> v('999.99', {})
>>> v('-99.99', {})
>>> v('-999.99', {})  # This should succeed
Traceback (most recent call last):
django.core.validators.ValidationError: [u'Please enter a valid decimal number with at most 5 total digits.']

This error affects django.core.validators.IsValidDecimal and django.newforms.fields.DecimalField.

The attached patch fixes the problem and adds a regression test for it

Attachments (1)

decimalfield.diff (1.7 KB) - added by Andrew Durdin <adurdin@…> 9 years ago.

Download all attachments as: .zip

Change History (4)

Changed 9 years ago by Andrew Durdin <adurdin@…>


comment:1 Changed 9 years ago by Simon G. <dev@…>

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 9 years ago by gwilson

  • Resolution set to fixed
  • Status changed from new to closed

(In [6067]) Fixed #5232 -- Fixed the validation of DecimalField so that the negative sign is not counted as a digit. Thanks, Andrew Durdin.

comment:3 Changed 9 years ago by gwilson

  • Summary changed from DecimalField max_digits counts -ve sign as a digit. to DecimalField max_digits counts negative sign as a digit.
Note: See TracTickets for help on using tickets.
Back to Top