Edgewall Software

Opened 12 years ago

Closed 11 years ago

Last modified 11 years ago

#10322 closed defect (fixed)

trac.util.datefmt - strftime format must be str

Reported by: guidod-2007-@… Owned by: guidod-2007-@…
Priority: normal Milestone: 0.12.3
Component: general Version: 0.12.2
Severity: normal Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:


I was testing a plugin (JsGantt) on Python 2.4 (CentOs 5) experiencing an error message saying:

 strftime() argument 1 must be str, not unicode

which is provoked right there in trac/util/datefmt.py - the reason is that the argument to format_datetime is not checked in any way, and if it is unicode then python 2.4 will reject it. The fix is easy: just wrap "format" in "str()".

(I assume that the JsGantt read the format from a trac.config item passing it through without looking at it. I haven't tested that though)

Attachments (1)

trac.format_datetime.no-unicode-01.patch (405 bytes ) - added by guidod-2007-@… 12 years ago.

Download all attachments as: .zip

Change History (5)

by guidod-2007-@…, 12 years ago

comment:1 by Remy Blank, 12 years ago

I'm not sure if we should do that unconditionally, or have a strftime() in trac.util.compat for 2.4 only.

comment:2 by guidod-2007-@…, 12 years ago


  • the datefmt is commonly used to define the order and resolution - that is naturally an ascii string so I did not consider to look for the encoding that would match best here.
  • also there is only one strftime in the trac core, so any workaround could live in datefmt - may be some isinstance check.

So, if you want to be really strict then one could move up the platform-encoding-detection and use it for the strftime-format-encoding in case there was a unicode argument.

comment:3 by Remy Blank, 11 years ago

Resolution: fixed
Status: newclosed

The same issue is also present in Python 2.5. At first, I wanted to encode the format before passing it to strftime(), but Python 2.7 converts unicode format arguments with the ascii codec anyway. So we might as well do the same before calling strftime().

Patch applied in [10828]. Thanks!

comment:4 by Remy Blank, 11 years ago

Owner: set to guidod-2007-@…

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain guidod-2007-@….
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from guidod-2007-@… to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.