Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#10825 closed (fixed)

Template filter date 'U' raises an AttributeError under certain circumstances

Reported by: Matthias Kestenholz Owned by: Michael Radziej
Component: Template system Version: master
Severity: Keywords: template date
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

While fixing #10048 in [9919] a new bug has been introduced. Around line 200 in django/utils/dateformat.py:

    def U(self):
        "Seconds since the Unix epoch (January 1 1970 00:00:00 GMT)"
        off = self.timezone and self.timezone.utcoffset(self.data) or 0
        return int(time.mktime(self.data.timetuple())) + off.seconds * 60

If self.timezone and self.timezone.utfoffset(self.data) evaluates to False, Django tries to access off.seconds but off is 0 => An AttributeError (int has no attribute seconds) is raised.

Unfortunately I do not know enough about the timezone handling to provide a test or even a fix.

Attachments (3)

utils_dateformat-r10651.patch (4.2 KB) - added by George Song 8 years ago.
'U' implementation, tests, and documentation
10825-utils_dateformat-r10651.patch (4.2 KB) - added by George Song 8 years ago.
Same as last patch, but removed unnecessary self.timezone check
10825.diff (4.5 KB) - added by Michael Radziej 8 years ago.
patch inluding fix of testcases, replaces older patch

Download all attachments as: .zip

Change History (13)

comment:1 Changed 8 years ago by Alex Gaynor

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Karen Tracey

See also #9850. Note U is documented as "not implemented" and near as I can tell the code before this change didn't work properly either (though I guess perhaps it didn't raise an AttributeError).

comment:3 Changed 8 years ago by George Song

Owner: changed from nobody to George Song
Status: newassigned

Changed 8 years ago by George Song

'U' implementation, tests, and documentation

Changed 8 years ago by George Song

Same as last patch, but removed unnecessary self.timezone check

comment:4 Changed 8 years ago by George Song

Has patch: set

Provided patch to let Python do its timezone thing, instead of futzing with offsets, etc.

comment:5 Changed 8 years ago by Matthias Kestenholz

This patch works for me, thanks.

comment:6 Changed 8 years ago by Michael Radziej

Owner: changed from George Song to Michael Radziej
Status: assignednew

comment:7 Changed 8 years ago by Michael Radziej

the patch breaks the dateformat tests. I'm fixing ...

Changed 8 years ago by Michael Radziej

Attachment: 10825.diff added

patch inluding fix of testcases, replaces older patch

comment:8 Changed 8 years ago by Michael Radziej

Triage Stage: AcceptedReady for checkin

Fix issues with epoch values in util.datetime.

  • fix handling of data without timezone
  • fix handling of time zones and DST (you really should not multiply seconds in the first place!)

I double-checked that this now gives correct results with other services on the Internet.

comment:9 Changed 8 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [10716]) Fixed #10825: fixed the 'U' format code to dateformat (and the date/now filter/tag). Thanks to gsong and mir.

comment:10 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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