#27039: ModelFields with 'default' value set and 'required'=False in form does 
not
use default value
-------------------------------------+-------------------------------------
     Reporter:  Ivan Belokobylskiy   |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Forms                |                  Version:  1.10
     Severity:  Release blocker      |               Resolution:  fixed
     Keywords:  default non-         |             Triage Stage:  Accepted
  required modelform                 |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by ljsjl):

 I've run into what I would call a bug (or at least unexpected - to me -
 behaviour) which is related to this, running Django 1.11.1. I'm happy to
 break this out into another ticket if you'd prefer.

 While the argument can be made for a user submitted blank/empty string
 overriding the field default, does this make sense in the case of an
 IntegerField (or any number field really)? If I have e.g.
 models.IntegerField(blank=True, default=0) in a model then currently a
 user can submit a blank value to a ModelForm for this model by deleting
 the field initial value, and the field value will travel through
 form/model cleaning as None.

 If I then have couple of IntegerFields like the above and model.clean()
 does a check on their sum, it will fail when attempting to add NoneType. I
 would say it is reasonable to expect a number based field to contain a
 number by the time it hits model.clean() via a form, either a valid user
 submitted value or default if the submitted field is empty. Obviously I
 can guard the arithmetic statement with a test or try: clause, but in my
 mind I set a default value so I expect to see something valid. Maybe
 others expect otherwise :)

--
Ticket URL: <https://code.djangoproject.com/ticket/27039#comment:19>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/064.245eeac704a272d11714ab21e34642f4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to