Opened 8 years ago
Closed 8 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 , 8 years ago
| Component: | Uncategorized → Core (Other) |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Bug |
| Version: | 1.11 → master |
comment:2 by , 8 years ago
| Has patch: | set |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
comment:3 by , 8 years ago
| Cc: | added |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
comment:6 by , 8 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → new |
Running version Django==2.0.1
With Example form
class UpdateBalanceForm(forms.Form):
id = forms.ModelChoiceField(ProductPortfolio.objects.all(), required=True)
balance = forms.DecimalField(decimal_places=2, max_digits=16, required=True)
Running the following you get
form = UpdateBalanceForm({'id':1, 'balance':Decimal('5.420575188741E-12')})
form.is_valid()
False
form.errors
{'id': ['Select a valid choice. That choice is not one of the available choices.'], '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
Version 0, edited 8 years ago by (next)
comment:7 by , 8 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Please open a new ticket as the fix for this ticket has been released.
Note:
See TracTickets
for help on using tickets.
PR