Strange interaction with django

0 views
Skip to first unread message

Iwan Vosloo

unread,
Aug 7, 2009, 10:32:05 AM8/7/09
to Paste Users
Hi there,

We have a really strange issue when using webob and django.templates
together. Any help to try and get around it would be greatly
appreciated. The code causing the breakage does not have anything
logical to do with the breaking code. THere must be some strange side-
effect.

I think its easier to try and look for it from the webob side, hence
my posing it here (see below).

We are on webob 0.9.4 and django 0.96.1

Thanks
- Iwan


from datetime import datetime
from webob import Response, UTC

import os
os.environ['DJANGO_SETTINGS_MODULE'] = '__main__' # Just to simplify
things
import django.template

templ = django.template.Template('source', 'afile') # Comment out this
line and it works

resp = Response()
stamp = datetime.fromtimestamp(123.4, tz=UTC)
resp.last_modified = stamp # Stepping into the code, this seems to
be setting things correctly
print stamp
print resp.last_modified #But something goes wrong in
translating it back to an object
assert resp.last_modified == stamp # This breaks, the reconstructed
time is 8 hours out

Ian Bicking

unread,
Aug 7, 2009, 12:24:02 PM8/7/09
to Iwan Vosloo, Paste Users
Huh, I can't reproduce, though maybe I have different versions of things.  Or maybe the way my timezone is set is different (I think my machine uses UTC?)

To see what WebOb is doing exactly, look at resp.headers['last-modified'] -- setting last_modified will change the header immediately, and accessing .last_modified will re-parse that header.  I expect the serialization wouldn't be effected (since it's pretty isolated to WebOb), but maybe Django somehow effects the parsing?

Iwan Vosloo

unread,
Aug 7, 2009, 1:57:27 PM8/7/09
to Paste Users

Hi Ian,

I have narrowed the affected code down to a call to time.mktime in def
mktime_tz in module rfc822. This is called when webob tries to re-
parse the header. (The header is set correctly.)

I supposed that since many methods in time can be influenced by stuff
in locale, django may have fiddled with locale. But, I can't find
such fiddling in django.

The problem disappears with django 1.0.2, so I've decided it must be
django's fault :-)

(We're on python 2.5, BTW.)

Thanks
- Iwan
Reply all
Reply to author
Forward
0 new messages