Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#213 closed defect (fixed)

error submitting empty times

Reported by: jkocherhans@… 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 (last modified by Jacob)

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/", line 63, in get_response
    return callback(request, **param_dict)

  File "/usr/local/lib/python2.4/site-packages/django/views/admin/", line 767, in add_stage

  File "/opt/local/lib/python2.4/site-packages/django/core/", 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/", line 654, in html2python
    time_tuple = time.strptime(data, '%H:%M:%S')

  File "/usr/local/lib/python2.4/", 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/
--- django/core/   (revision 331)
+++ django/core/   (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
                 time_tuple = time.strptime(data, '%H:%M:%S')

Change History (2)

comment:1 Changed 14 years ago by Jacob

Description: modified (diff)

comment:2 Changed 14 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

(In [702]) Fixed #213 -- Improved formfields.TimeField.html2python() so that it doesn't fail for None input

Note: See TracTickets for help on using tickets.
Back to Top