Django

Code

Ticket #5232 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

DecimalField max_digits counts negative sign as a digit.

Reported by: Andrew Durdin <adurdin@gmail.com> Assigned to: adrian
Milestone: Component: Validators
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

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

decimalfield.diff (1.7 kB) - added by Andrew Durdin <adurdin@gmail.com> on 08/23/07 03:48:12.
Patch

Change History

08/23/07 03:48:12 changed by Andrew Durdin <adurdin@gmail.com>

  • attachment decimalfield.diff added.

Patch

08/23/07 03:50:58 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch changed.
  • has_patch set to 1.
  • stage changed from Unreviewed to Ready for checkin.
  • needs_tests changed.
  • needs_docs changed.

09/08/07 14:24:47 changed by gwilson

  • status changed from new to closed.
  • resolution set to fixed.

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

09/08/07 14:26:34 changed by gwilson

  • summary changed from DecimalField max_digits counts -ve sign as a digit. to DecimalField max_digits counts negative sign as a digit..

Add/Change #5232 (DecimalField max_digits counts negative sign as a digit.)




Change Properties
Action