Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#219 closed defect (fixed)

The change history for an object is recording changes with a 6-hour offset to the timestamp

Reported by: fidothe Owned by: adrian
Component: contrib.admin Version:
Severity: major Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


From the tutorial: /admin/polls/polls/1/history/ is recording changes made to the object, but the timestamp for the changes is 6 hours out (reading 5:12 AM rather than 11:12 AM).

Change History (6)

comment:1 Changed 10 years ago by edgars

Fidothe: do you have your timezone set?
It should probably be a TIME_ZONE='Europe/Paris' type variable in yourproject.settings.main, but TZ=Europe/City variable in environment (if the os is *nix type) works better for me.

comment:2 Changed 10 years ago by hugo <gb@…>

When setting TIME_ZONE = 'Europe/Berlin' in the settings file, the following happens when accessing the history:

There's been an error:

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/django-1.0.0-py2.3.egg/django/core/handlers/", line 60, in get_response
    response = middleware_method(request, callback, param_dict)

  File "/usr/lib/python2.3/site-packages/django-1.0.0-py2.3.egg/django/middleware/", line 34, in process_view
    if self.user_is_valid(request.user):

  File "/usr/lib/python2.3/site-packages/django-1.0.0-py2.3.egg/django/core/handlers/", line 94, in _get_user

  File "/usr/lib/python2.3/site-packages/django-1.0.0-py2.3.egg/django/core/handlers/", line 77, in _load_session_and_user
    self._session = sessions.get_session_from_cookie(session_cookie)

  File "/usr/lib/python2.3/site-packages/django-1.0.0-py2.3.egg/django/models/", line 214, in _module_get_session_from_cookie
    return get_object(session_md5__exact=session_md5, select_related=True)

  File "/usr/lib/python2.3/site-packages/django-1.0.0-py2.3.egg/django/core/", line 87, in _curried
    return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items()))

  File "/usr/lib/python2.3/site-packages/django-1.0.0-py2.3.egg/django/core/", line 1032, in function_get_object
    obj_list = function_get_list(opts, klass, **kwargs)

  File "/usr/lib/python2.3/site-packages/django-1.0.0-py2.3.egg/django/core/", line 1059, in function_get_list
    for row in cursor.fetchall():

  File "/usr/lib/python2.3/site-packages/django-1.0.0-py2.3.egg/django/core/db/", line 30, in typecast_timestamp
    int(times[0]), int(times[1]), int(seconds.split('-')[0]),

ValueError: invalid literal for int(): 17+02

comment:3 Changed 10 years ago by hugo <gb@…>

And export TZ=Europe/Berlin doesn't change the time reference - I get the wrong time, as if I hadn't set it. Local time is 16:17 CEST, stored time is 09:17 ...

comment:5 Changed 10 years ago by hugo <gb@…>

The problem is in django/db/ in line 30. There django assumes that the timezone and the seconds are delimited by '-' - but in case of Europe it's a '+' sign. So actually it's much better to just pull the first two chars from the seconds stuff instead of using the split. Line 29-31 could look like this:

    return datetime.datetime(int(dates[0]), int(dates[1]), int(dates[2]),
        int(times[0]), int(times[1]), int(seconds[:2]),

I didn't check the microseconds-Stuff, though.

comment:6 Changed 10 years ago by adrian

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

(In [346]) Fixed #219 and #188 -- Database timestamp typecast no longer assumes '-' delineates the time zone

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