Opened 19 years ago
Last modified 18 years ago
#213 closed defect
error submitting empty times — at Initial Version
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | contrib.admin | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If I try to submit a datetime field in the admin interface, and the time is not provided (I'm setting disabled=true on the field with javascript), I get the following traceback:
Traceback (most recent call last):
File "/usr/local/lib/python2.4/site-packages/django/core/handlers/base.py", line 63, in get_response
return callback(request, param_dict)
File "/usr/local/lib/python2.4/site-packages/django/views/admin/main.py", line 767, in add_stage
manipulator.do_html2python(new_data)
File "/opt/local/lib/python2.4/site-packages/django/core/formfields.py", line 98, in do_html2python
new_data.setlist(field.field_name, [field.class.html2python(None)])
File "/opt/local/lib/python2.4/site-packages/django/core/formfields.py", line 654, in html2python
time_tuple = time.strptime(data, '%H:%M:%S')
File "/usr/local/lib/python2.4/_strptime.py", line 290, in strptime
found = format_regex.match(data_string)
TypeError: expected string or buffer
Here's a diff against 331 that fixes the problem. (I don't know if this is a use-case you want to deal with, but the fix seems pretty trivial.)
Index: django/core/formfields.py
===================================================================
--- django/core/formfields.py (revision 331)
+++ django/core/formfields.py (working copy)
@@ -649,6 +649,8 @@
def html2python(data):
"Converts the field into a datetime.time object"
import time, datetime
+ if data is None:
+ return None
try:
try:
time_tuple = time.strptime(data, '%H:%M:%S')