Django

Code

Ticket #4630 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

SplitDateTimeField - TypeError when required=False and data not entered

Reported by: Glin <glin@seznam.cz> Assigned to: adrian
Milestone: Component: Forms
Version: newforms-admin Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

possible_patch_fields.py.diff (0.7 kB) - added by Glin <glin@seznam.cz> on 06/20/07 04:04:12.
splitdatetimefield.patch (2.6 kB) - added by SmileyChris on 06/20/07 06:16:20.

Change History

06/20/07 04:03:46 changed by Glin <glin@seznam.cz>

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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?

06/20/07 04:04:12 changed by Glin <glin@seznam.cz>

  • attachment possible_patch_fields.py.diff added.

06/20/07 06:16:20 changed by SmileyChris

  • attachment splitdatetimefield.patch added.

06/20/07 06:21:25 changed by SmileyChris

  • has_patch set to 1.
  • summary changed from [newforms-admin] SplitDateTimeField - !TypeError when datetime is blank=True,null=True to SplitDateTimeField - TypeError when required=False and data not entered.
  • component changed from Admin interface to django.newforms.
  • 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.

06/22/07 22:32:59 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #4630 (SplitDateTimeField - TypeError when required=False and data not entered)




Change Properties
Action