Code

Opened 7 years ago

Closed 7 years ago

#4630 closed (fixed)

SplitDateTimeField - TypeError when required=False and data not entered

Reported by: Glin <glin@…> Owned by: adrian
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@…> 7 years ago.
splitdatetimefield.patch (2.6 KB) - added by SmileyChris 7 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 Changed 7 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 7 years ago by Glin <glin@…>

Changed 7 years ago by SmileyChris

comment:2 Changed 7 years ago by SmileyChris

  • Component changed from Admin interface to django.newforms
  • Has patch set
  • Summary changed from [newforms-admin] SplitDateTimeField - !TypeError when datetime is blank=True,null=True to SplitDateTimeField - TypeError when required=False and data not entered
  • Triage Stage changed from Unreviewed to Ready 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 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.