Opened 7 years ago

Closed 6 years ago

#28562 closed Bug (fixed)

DecimalValidator raises ValidationError for decimals in scientific notation

Reported by: Maksim Iakovlev Owned by: Josh Schneier
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Tim Martin Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

>>> validator = DecimalValidator(20, 2)
>>> value = Decimal('7.42403889818E+17')
>>> try:
...     validator(value)
... except Exception as e:
...     print(e)
... 
[u'Ensure that there are no more than 2 decimal places.']
>>> value = Decimal(742403889818000000)
>>> try:
...     validator(value)
... except Exception as e:
...     print(e)
... 
>>> 

Change History (7)

comment:1 by Josh Schneier, 7 years ago

Component: UncategorizedCore (Other)
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug
Version: 1.11master

comment:2 by Josh Schneier, 7 years ago

Has patch: set
Owner: changed from nobody to Josh Schneier
Status: newassigned

comment:3 by Tim Martin, 7 years ago

Cc: Tim Martin added
Triage Stage: AcceptedReady for checkin

comment:4 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In e8c45963:

Fixed #28562 -- Fixed DecimalValidator handling of positive exponent scientific notation.

comment:5 by Tim Graham <timograham@…>, 7 years ago

In 7c6590af:

[2.0.x] Fixed #28562 -- Fixed DecimalValidator handling of positive exponent scientific notation.

Backport of e8c45963296eb8bf3938bf9ece30b585a8cbb097 from master

comment:6 by Josh Harwood, 6 years ago

Resolution: fixed
Status: closednew

Running version Django==2.0.1

With Example form

class UpdateBalanceForm(forms.Form):
    balance = forms.DecimalField(decimal_places=2, max_digits=16, required=True)

Running the following you get

form = UpdateBalanceForm({'balance':Decimal('5.420575188741E-12')})
form.is_valid()
False
form.errors
{'balance': ['Ensure that there are no more than 16 digits in total.']}

This is surprising because the value has 13 digits minus the scientific notation

edit 1: Simplified example

Last edited 6 years ago by Josh Harwood (previous) (diff)

comment:7 by Tim Graham, 6 years ago

Resolution: fixed
Status: newclosed

Please open a new ticket as the fix for this ticket has been released.

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