#20205: PositiveIntegerfield does not handle empty values well
-------------------------------------+-------------------------------------
     Reporter:  anonymous            |                    Owner:  Amine
                                     |  Zyad
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Brenton Partridge):

 For others who might come across this error, check to make sure that you
 (and your colleagues' code) are using a forms.IntegerField and not a
 forms.CharField (or similar). forms.IntegerField, if left blank by the
 submitter, will send None to the model field, but forms.CharField will
 send an empty string which triggers OP's error.

 That said, this is a way for someone to shoot themselves in the foot, and
 the error message could be cleaner. One possible way forward would be for
 `Field.get_prep_value` to check if the field has `empty_strings_allowed =
 False`, and if so and if the value is an empty string, to throw some type
 of error with a more meaningful error message. That said, it's not
 strictly necessary, as someone will likely find this very thread from the
 current error message, and realize what the problem is.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20205#comment:23>
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 post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.79904b9b2cc5f0004f3be1df75e43df5%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to