Opened 13 years ago

Closed 13 years ago

Last modified 12 years ago

#557 closed defect (fixed)

date_hierarchy doesn't work with DateField

Reported by: kyrrigle@… Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: normal Keywords:
Cc: kyrrigle@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Trying to use a DateField in the meta.Admin(date_hierarch="dateFld") yields the following exception when going to the admin list page:

  File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/db/", line 23, in typecast_timestamp
    d, t = s.split()

A simple patch to make typecast_timestamp work with just dates is:

--- django/core/db/ (revision 687)
+++ django/core/db/ (working copy)
@@ -20,7 +20,12 @@
     # "2005-07-29 15:48:00.590358-05"
     # "2005-07-29 09:56:00-05"
     if not s: return None
-    d, t = s.split()
+    flds = s.split()
+    d = flds[0]
+    if len(flds) == 1:
+        t = "00:00:01"  # or noon?
+    else:
+        t = flds[1]
     # Extract timezone information, if it exists. Currently we just throw
     # it away, but in the future we may make use of it.
     if '-' in t:

Change History (6)

comment:1 Changed 13 years ago by Adrian Holovaty

That's strange -- it should work. Can you paste the offending model?

comment:2 Changed 13 years ago by kyrrigle@…

Cc: kyrrigle@… added

Just change the polls example pub_date to be a meta.DateField, sqlreset and add a poll.

Full stack trace:

There's been an error:

Traceback (most recent call last):

  File "D:\django-trunk\django\core\handlers\", line 64, in get_response
    response = callback(request, **param_dict)

  File "D:\django-trunk\django\views\admin\", line 327, in change_list
    for year in getattr(lookup_mod, 'get_%s_list' % field_name)('year', **lookup_params):

  File "D:\django-trunk\django\utils\", line 3, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "D:\django-trunk\django\core\meta\", line 1387, in function_get_date_list
    return [typecast_timestamp(str(row[0])) for row in cursor.fetchall()]

  File "D:\django-trunk\django\core\db\", line 23, in typecast_timestamp
    d, t = s.split()

ValueError: unpack list of wrong size

comment:3 Changed 13 years ago by Adrian Holovaty

Resolution: worksforme
Status: newclosed

I did that, and it worked fine for me. I also verified it on a completely separate model that I'm developing, and it worked fine, too. I suspect you forgot to do sqlreset, or have some other bug in your model.

comment:4 Changed 13 years ago by Esaj <jason at>

Resolution: worksforme
Status: closedreopened

I'm getting this problem too. It seems that s is equal to the string 'None' when this happens. I'm using SQLite.

comment:5 Changed 13 years ago by mildly@…

This is exactly the same problem (and solution) I ran into when using date-based generic views with SQLite 'Date' fields.

It's because a Date field only returns the date, whereas the typecasts function expects the date and time.

I am currently working on updating the SQLite3 wrapper to use SQLite's internal date handling functions.

comment:6 Changed 13 years ago by Malcolm Tredinnick <malcolm@…>

Resolution: fixed
Status: reopenedclosed

This was fixed in [1971] as part of ticket #1062.

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