django.forms.DecimalField can not validate scientific notation

35 views
Skip to first unread message

Shiplu Mokaddim

unread,
Sep 14, 2022, 8:38:32 AM9/14/22
to Django users
In django 1.11 this code works.

from django.forms.fields import DecimalField
>>> DecimalField(max_digits=8, decimal_places=7).clean('0')
Decimal('0')
>>> DecimalField(max_digits=8, decimal_places=7).clean('0.0')
Decimal('0.0')
>>> DecimalField(max_digits=8, decimal_places=7).clean('0E+1')
Decimal('0E+1')

But in django 2.0.13 we have 
>>> DecimalField(max_digits=8, decimal_places=7).clean('0E+1')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/amokaddim/e/fh/lib/python3.8/site-packages/django/forms/fields.py", line 150, in clean
    self.run_validators(value)
  File "/Users/amokaddim/e/fh/lib/python3.8/site-packages/django/forms/fields.py", line 141, in run_validators
    raise ValidationError(errors)
django.core.exceptions.ValidationError: <exception str() failed>


I have two questions, 

1. Is there any way I can prevent this validation error from happening in Django 2.0? Any flag or option that will prevent this?
2. We are upgrading Django to the latest. Will it be solved in the later version?

Now I have a override of the to_python method. It just calls DecimalField.normalize(). But I am not sure if this is the right way to do it.

subin

unread,
Sep 16, 2022, 4:14:08 PM9/16/22
to django...@googlegroups.com
Thank you for your recent purchase from ! Please contact us if you have any questions or visit our website:

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/eb5f4df2-e29d-4c2a-a334-99bcfa1ece50n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages