﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
4317	Fix compress() in SplitDateTimeField	ctdecci@…		"If a !SplitDateTimeField is not required, and one or both of the date/time fields is None, then datetime.datetime.combine() raises an exception within the compress() method.  The current test ""if data_list:"" (shown below) will only fail if passed an empty list/tuple.  If data_list is a non-empty list containing a None value (because one or both of the date/time fields are blank), then the ""if data_list:"" test still passes, and datetime.datetime.combine() raises an exception.

Snippet from compress() method of !SplitDateTimeField class:
{{{
if data_list:
    return datetime.datetime.combine(*data_list)
}}}

Given this model:
{{{
from django.db import models

class Foo(models.Model):
    date = models.DateTimeField(blank=True, null=True)
}}}

Here is an example:
{{{
>>> from scinet.test.models import Foo
>>> from django import newforms as forms
>>> Form = forms.form_for_model(Foo)
>>> Form.base_fields['date'] = forms.fields.SplitDateTimeField(required=False, widget=forms.widgets.SplitDateTimeWidget)
>>> f = Form({'date_0': None, 'date_1': None})
>>> f.errors
Traceback (most recent call last):
  File ""<console>"", line 1, in ?
  File ""/usr/lib/python2.4/site-packages/django/newforms/forms.py"", line 93, in _errors
    self.full_clean()
  File ""/usr/lib/python2.4/site-packages/django/newforms/forms.py"", line 187, in full_clean
    value = field.clean(value)
  File ""/usr/lib/python2.4/site-packages/django/newforms/fields.py"", line 473, in clean
    return self.compress(clean_data)
  File ""/usr/lib/python2.4/site-packages/django/newforms/fields.py"", line 493, in compress
    return datetime.datetime.combine(*data_list)
TypeError: combine() argument 1 must be datetime.date, not None
}}}

I've attached a patch that checks data_list for empty values, verifies that (in the case of non-required fields) either both are blank or both are non-blank, and raises an exception otherwise."		closed	Forms	dev		duplicate			Accepted	1	0	1	0	0	0
