Opened 9 years ago

Closed 9 years ago

#4630 closed (fixed)

SplitDateTimeField - TypeError when required=False and data not entered

Reported by: Glin <glin@…> Owned by: Adrian Holovaty
Component: Forms Version: newforms-admin
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When datetime db field (in model) is blank=True, null=True, then I get TypeError when submit(save) form for this model with no date and/or time filled in:

TypeError at /admin/cms/article/239/
combine() argument 1 must be datetime.date, not None
Request Method: 	POST
Request URL: 	http://127.0.0.1:8000/admin/cms/article/239/
Exception Type: 	TypeError
Exception Value: 	combine() argument 1 must be datetime.date, not None
Exception Location: 	/usr/lib/python2.4/site-packages/django/newforms/fields.py in compress, line 561
Python Executable: 	/usr/bin/python
Python Version: 	2.4.3

Here are last few lines of traceback:

 File "/usr/lib/python2.4/site-packages/django/newforms/forms.py" in _get_errors
  93. self.full_clean()
File "/usr/lib/python2.4/site-packages/django/newforms/forms.py" in full_clean
  206. value = field.clean(value)
File "/usr/lib/python2.4/site-packages/django/newforms/fields.py" in clean
  541. return self.compress(clean_data)
File "/usr/lib/python2.4/site-packages/django/newforms/fields.py" in compress
  561. return datetime.datetime.combine(*data_list)

Attachments (2)

possible_patch_fields.py.diff (767 bytes) - added by Glin <glin@…> 9 years ago.
splitdatetimefield.patch (2.6 KB) - added by Chris Beaven 9 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 9 years ago by Glin <glin@…>

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

I'm not sure, that I know how to fix this bug correctly. I think the bug is on line 521 in fields.py:

        elif not self.required and not value:

IHMO value is always list of values from fields, so "not value" is not a proper condition. I created patch which checks all values in list "value" (look at patch). Is that correct fix for this bug?

Changed 9 years ago by Glin <glin@…>

Changed 9 years ago by Chris Beaven

Attachment: splitdatetimefield.patch added

comment:2 Changed 9 years ago by Chris Beaven

Component: Admin interfacedjango.newforms
Has patch: set
Summary: [newforms-admin] SplitDateTimeField - !TypeError when datetime is blank=True,null=TrueSplitDateTimeField - TypeError when required=False and data not entered
Triage Stage: UnreviewedReady for checkin

This is a more complete fix for the bug. Compress should still do some logic if it requires all the fields to be there if it required=False.

Tests included.

comment:3 Changed 9 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [5515]) Fixed #4630 -- Fixed some validation problems with SplitDateTimeField. Thanks
glin@… and SmileyChris.

Note: See TracTickets for help on using tickets.
Back to Top