#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 Matt Davis):

 I am noticing an odd behavior upgrading a Django app and I have traced it
 to this ticket.  I have upgraded the app from 1.8 to 1.10 and all tests
 are passing, however if I upgrade from 1.10 to 1.10.1 one of my tests
 fail.  I have determined the reason why to be its a ModelForm and the
 model has a field defined with a default value:

 {{{
 field_x = models.CharField(max_length=100, db_index=True, blank=True,
 default='')
 }}}

 The model form also has a clean method that if a value isn't supplied for
 field_x that it will generate one:

 {{
 def clean_field_x(self):
     token = self.cleaned_data.get('field_x')
     if not token:
         token = utils.generate_token()
     return token
 }}

 It would appear that in 1.10.1 it changed from using the generated token
 in the clean method, to then preferring the model field's default value.
 I think this behavior is incorrect, shouldn't it prefer the form's cleaned
 data over the model defaults?

--
Ticket URL: <https://code.djangoproject.com/ticket/27039#comment:17>
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/064.d6d525f23f258e8a3ae19b57b482013e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to