#35304: IntegerField trailing decimal and zeros
               Reporter:  Piotr Kotarba  |          Owner:  nobody
                   Type:  Uncategorized  |         Status:  new
              Component:  Forms          |        Version:  5.0
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
 I have a little concern in regard of stripping trailing decimal and zeros.

 IntegerField Uses NumberInput as widget, which allows to pass Numbers with
 trailing zeros.
 For example, below numbers are valid:

 Shouldn't IntegerField accept only Integers?

 Below method uses _lazy_re_compile to get rid of them.

     def to_python(self, value):
         Validate that int() can be called on the input. Return the result
         of int() or None for empty values.
         value = super().to_python(value)
         if value in self.empty_values:
             return None
         if self.localize:
             value = formats.sanitize_separators(value)
         # Strip trailing decimal and zeros.
             value = int(self.re_decimal.sub('', str(value)))
         except (ValueError, TypeError):
             raise ValidationError(self.error_messages['invalid'],
         return value

 I have found related issue:

 The reason of this functionality as I understand was:
 "Django forms are useful for validating user input beyond just HTML
 "One issue, MS Excel represents all numbers in cells as floats, even
 integers. So for this to work, a float with value 1.0 should be cleaned by
 forms.IntegerField as 1. "

 I am sceptic to this solution, and as Django main purpose is to be used on
 HTML, it shouldn't have such functionality in its core.
 Also I think that this issue was created when there was no inputs, and
 HTML looked different as well. Lots have changed since then.

 What do you think?
Ticket URL: <https://code.djangoproject.com/ticket/35304>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 

Reply via email to