django-postmark icon indicating copy to clipboard operation
django-postmark copied to clipboard

MySQL backend does not support timezone-aware datetimes.

Open tijs opened this issue 13 years ago • 2 comments

I get this error when using the postmark app locally (where i use MySQL). This ValueError seems to be raised by the post_send.send method.

tijs avatar Aug 16 '11 09:08 tijs

I'm seeing the same issue. It's in models.py. The block of code looks like this:

    timestamp, tz = resp["SubmittedAt"].rsplit("+", 1)
    tz_offset = int(tz.split(":", 1)[0])
    tz = timezone("Etc/GMT%s%d" % ("+" if tz_offset >= 0 else "-", tz_offset))
    submitted_at = tz.localize(datetime.strptime(timestamp[:26], POSTMARK_DATETIME_STRING)).astimezone(pytz.utc)

I added the following bit as a temporary fix for me, but it is certainly not the right solution. I assume the right solution would be to detect the database and not do the above line of code if it's MySQL (or there may be away to detect whether the database supports timezone-aware date/time)

        submitted_at = submitted_at.replace(tzinfo=None)

I also wonder if storing the date in UTC and letting the front-end worry about displaying it in the correct timezone might be the way to go.

JoeKueser avatar Aug 18 '11 17:08 JoeKueser

"I also wonder if storing the date in UTC and letting the front-end worry about displaying it in the correct timezone might be the way to go." well that does seem to be general practice as MySQL is not the only Django supported db that does not know how to store timezone aware timestamps.

tijs avatar Aug 19 '11 08:08 tijs