Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#10825 closed (fixed)

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

Reported by: mk Owned by: mir
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 gsong 6 years ago.
'U' implementation, tests, and documentation
10825-utils_dateformat-r10651.patch (4.2 KB) - added by gsong 6 years ago.
Same as last patch, but removed unnecessary self.timezone check
10825.diff (4.5 KB) - added by mir 6 years ago.
patch inluding fix of testcases, replaces older patch

Download all attachments as: .zip

Change History (13)

comment:1 Changed 6 years ago by Alex

  • milestone set to 1.1
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by kmtracey

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 6 years ago by gsong

  • Owner changed from nobody to gsong
  • Status changed from new to assigned

Changed 6 years ago by gsong

'U' implementation, tests, and documentation

Changed 6 years ago by gsong

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

comment:4 Changed 6 years ago by gsong

  • Has patch set

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

comment:5 Changed 6 years ago by mk

This patch works for me, thanks.

comment:6 Changed 6 years ago by mir

  • Owner changed from gsong to mir
  • Status changed from assigned to new

comment:7 Changed 6 years ago by mir

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

Changed 6 years ago by mir

patch inluding fix of testcases, replaces older patch

comment:8 Changed 6 years ago by mir

  • Triage Stage changed from Accepted to Ready 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 6 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

(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 4 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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