Re: [Django] #34014: DecimalValidator fails to validate 0 in scientific notation (0E+1 or 0E+2) (was: django.forms.fields.DecimalValidator fails to validate 0 in scientific notation (0E+1 or 0E+2))

4 views
Skip to first unread message

Django

unread,
Sep 16, 2022, 12:10:30 AM9/16/22
to django-...@googlegroups.com
#34014: DecimalValidator fails to validate 0 in scientific notation (0E+1 or 0E+2)
-------------------------------------+-------------------------------------
Reporter: Shiplu Mokaddim | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 2.0
Severity: Normal | Resolution:
Keywords: DecimalValidator, | Triage Stage: Accepted
Decimal, DecimalField |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* cc: Josh Schneier (added)
* component: Forms => Core (Other)
* stage: Unreviewed => Accepted


Comment:

Thanks for the report. We should fix an edge case with `0`, maybe:
{{{#!diff
diff --git a/django/core/validators.py b/django/core/validators.py
index 473203a67e..446f97af10 100644
--- a/django/core/validators.py
+++ b/django/core/validators.py
@@ -487,7 +487,9 @@ class DecimalValidator:
)
if exponent >= 0:
# A positive exponent adds that many trailing zeros.
- digits = len(digit_tuple) + exponent
+ digits = len(digit_tuple)
+ if digit_tuple != (0,):
+ digits += exponent
decimals = 0
else:
# If the absolute value of the negative exponent is larger
than the

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34014#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages