Opened 19 years ago

Closed 19 years ago

Last modified 17 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 Holovaty
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: no UI/UX: no

Description

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 by edgars, 19 years ago

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 by hugo <gb@…>, 19 years ago

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/base.py", 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/admin.py", 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/wsgi.py", line 94, in _get_user
    self._load_session_and_user()

  File "/usr/lib/python2.3/site-packages/django-1.0.0-py2.3.egg/django/core/handlers/wsgi.py", 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/auth.py", 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/meta.py", 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/meta.py", 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/meta.py", 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/typecasts.py", line 30, in typecast_timestamp
    int(times[0]), int(times[1]), int(seconds.split('-')[0]),

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

comment:3 by hugo <gb@…>, 19 years ago

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 by hugo <gb@…>, 19 years ago

The problem is in django/db/typecasts.py 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]),
        int(microseconds.split('-')[0]))

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

comment:6 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(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