Opened 17 years ago

Closed 17 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: no UI/UX: no


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, not None
Request Method: 	POST
Request URL:
Exception Type: 	TypeError
Exception Value: 	combine() argument 1 must be, not None
Exception Location: 	/usr/lib/python2.4/site-packages/django/newforms/ 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/" in _get_errors
  93. self.full_clean()
File "/usr/lib/python2.4/site-packages/django/newforms/" in full_clean
  206. value = field.clean(value)
File "/usr/lib/python2.4/site-packages/django/newforms/" in clean
  541. return self.compress(clean_data)
File "/usr/lib/python2.4/site-packages/django/newforms/" in compress
  561. return datetime.datetime.combine(*data_list)

Attachments (2) (767 bytes ) - added by Glin <glin@…> 17 years ago.
splitdatetimefield.patch (2.6 KB ) - added by Chris Beaven 17 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by Glin <glin@…>, 17 years ago

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

        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?

by Glin <glin@…>, 17 years ago

by Chris Beaven, 17 years ago

Attachment: splitdatetimefield.patch added

comment:2 by Chris Beaven, 17 years ago

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 by Malcolm Tredinnick, 17 years ago

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