Opened 8 months ago

Closed 3 months 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: master
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 Changed 8 months ago by Josh Schneier

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

comment:2 Changed 8 months ago by Josh Schneier

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

comment:3 Changed 8 months ago by Tim Martin

Cc: Tim Martin added
Triage Stage: AcceptedReady for checkin

comment:4 Changed 7 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In e8c45963:

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

comment:5 Changed 7 months ago by Tim Graham <timograham@…>

In 7c6590af:

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

Backport of e8c45963296eb8bf3938bf9ece30b585a8cbb097 from master

comment:6 Changed 3 months ago by Josh Harwood

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 3 months ago by Josh Harwood (previous) (diff)

comment:7 Changed 3 months ago by Tim Graham

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