Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7064 closed (fixed)

Decimal validation doesn't correctly handle max_digits == decimal_places

Reported by: Craig Ogg Owned by: Karen Tracey
Component: Validators Version: master
Severity: Keywords: decimal validation
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If you have a decimal field defined in a model with max_digits and decimal_places set to the same value (for values 0 <= |n| < 1), you will get the following error message incorrectly when you enter any valid value:

  • Please enter a valid decimal number with a whole part of at most 0 digits.

You will also get the following error message incorrectly if the number you enter has decimal_places number of digits:

  • Please enter a valid decimal number with at most %s total digits.

This is because the leading 0 that str() produces is considered a digit in the validation code (e.g., .35 and 0.35 are treated as 3 digit numbers, with 0 as a digit in the "whole part").

Attachments (2)

fix-decimal-validation.diff (547 bytes) - added by Craig Ogg 8 years ago.
Corrected patch
7064.diff (968 bytes) - added by Marc Fargas 8 years ago.
added test.

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by Craig Ogg

Attachment: fix-decimal-validation.diff added

Corrected patch

comment:1 Changed 8 years ago by Marc Fargas

Needs documentation: unset
Needs tests: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

The patch should include a test that demostrates this behaviour (and that it's solved). I'll upload it in a while if you don't mind.

Changed 8 years ago by Marc Fargas

Attachment: 7064.diff added

added test.

comment:2 Changed 8 years ago by Marc Fargas

Needs tests: unset
Patch needs improvement: unset

Added a test case.

comment:3 Changed 8 years ago by Karen Tracey

Owner: changed from Craig Ogg to Karen Tracey
Status: newassigned

The code involved here is gone now but the problem still exists in form validation. max_digits == decimal_places is perfectly valid at the database level so Django should support it. As it is now you cannot bring up an existing valid decimal field defined in this way to the DB and simply re-save it using the admin interface.

comment:4 Changed 8 years ago by Karen Tracey

Resolution: fixed
Status: assignedclosed

(In [9387]) Fixed #7064: Made DemicmalField validation support max_digits equal to decimal_places.

comment:5 Changed 8 years ago by Karen Tracey

(In [9389]) [1.0.X] Fixed #7064: Made DemicmalField validation support max_digits equal to decimal_places.

r9387 and r9388 from trunk.

Note: See TracTickets for help on using tickets.
Back to Top