pyrax icon indicating copy to clipboard operation
pyrax copied to clipboard

StorageObject method 'last_modified' inconsistently returns UTC or naive timestamp

Open sheridanroberts opened this issue 11 years ago • 3 comments

Snippet:

obj_list = cont.get_objects()
for obj in obj_list:
    print "%s\t\t%s\t\t%s" % (obj.name, obj.total_bytes, obj.last_modified)
    dt = dateutil.parser.parse(obj.last_modified)
    dt = dt.astimezone(dateutil.tz.tzutc())
    print dt
    now = datetime.now(dateutil.tz.tzutc())
    print now
    duration = now-dt
    print duration.days

Output:

: onceler$ python -upload.py <Container '' -backup-20130508.zip 62818158 2013-05-08T16:53:32.937930Z 2013-05-08 16:53:32.937930+00:00 2013-09-20 05:24:23.073869+00:00 134 : onceler$ python -upload.py <Container '' -backup-20130508.zip 62818158 2013-05-08T16:53:32.937930 Traceback (most recent call last): File "confluence-upload.py", line 23, in dt = dt.astimezone(dateutil.tz.tzutc()) ValueError: astimezone() cannot be applied to a naive datetime : onceler$ python -upload.py <Container '' -backup-20130508.zip 62818158 2013-05-08T16:53:32.937930 Traceback (most recent call last): File "confluence-upload.py", line 23, in dt = dt.astimezone(dateutil.tz.tzutc()) ValueError: astimezone() cannot be applied to a naive datetime : onceler$ python -upload.py <Container '' -backup-20130508.zip 62818158 2013-05-08T16:53:32.937930Z 2013-05-08 16:53:32.937930+00:00 2013-09-20 05:27:32.915539+00:00 134

sheridanroberts avatar Sep 20 '13 16:09 sheridanroberts

I'm not able to reproduce this. Does this happen consistently, or more or less randomly?

EdLeafe avatar Sep 23 '13 14:09 EdLeafe

It happens randomly, it seems. I've had it work several times in a row, and then not work several times in a row. By "work" and "not work" I mean I was specifically looking for a UTC aware return. If you take my code snippet and run it say 50 times in a row, you should see different results several times in my experience.

sheridanroberts avatar Sep 25 '13 18:09 sheridanroberts

I ran it over 10,000 times, and I did not receive back a single timezone-aware value; they were all in a format like 2012-12-10T15:32:42.373660. IOW, "naive" datetime strings.

Could the difference be in how the objects were created/stored?

EdLeafe avatar Sep 27 '13 16:09 EdLeafe