#8898: `required` validation bypassed when using `DateTimeField` with
`SplitDateTimeWidget`.
---------------------------------------------+------------------------------
          Reporter:  mrmachine               |         Owner:  nobody           
                
            Status:  new                     |     Milestone:                   
                
         Component:  Forms                   |       Version:  SVN              
                
        Resolution:                          |      Keywords:  DateTimeField 
SplitDateTimeWidget
             Stage:  Design decision needed  |     Has_patch:  1                
                
        Needs_docs:  0                       |   Needs_tests:  0                
                
Needs_better_patch:  0                       |  
---------------------------------------------+------------------------------
Comment (by mrmachine):

 I was using a custom `DateTimeField` in my models which had a
 `formfield()` method that always used
 `django.contrib.localflavor.generic.forms.DateTimeField` as the form class
 so I wouldn't have to set input formats everywhere.

 This was overriding the form class specified in
 `BaseModelAdmin.formfield_for_dbfield` for `DateTimeField` db fields and
 exposing the validation bug in `forms.DateTimeField`, which was to bypass
 the "required" validation when used with `SplitDateTimeWidget`.

 In [9760] `ModelAdmin.formfield_for_dbfield` was re-factored and no longer
 treated my custom `DateTimeField` as a `models.DateTimeField`, because the
 new code checks if `db_field.__class__` is in `self.formfield_overrides`
 instead of using `isinstance()`.

 To summarise:

  - The bug in `forms.DateTimeField` when used with `SplitDateTimeWidget`
 still exists, though this combination is not normally found in Django
 core. I suggest that we should still remove this vestigial code to avoid
 confusion and make subclassing `forms.DateTimeField` easier. After all,
 `MultiWidget` should only be used with `MultiValueField`.

  - A new bug (I'd call it a bug - it is a change in behaviour) exists
 where subclassed model fields are not recognised as their parent class in
 `BaseModelAdmin.formfield_for_dbfield()`. I suppose the fix for this would
 be to loop over `self.formfield_overrides` and check with `isinstance()`
 in each iteration. When there's a match, update `kwargs` and return.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8898#comment:12>
Django <http://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 post to this group, send email to django-updates@googlegroups.com
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to