#10322 closed defect (fixed)
trac.util.datefmt - strftime format must be str
| Reported by: | Owned by: | ||
|---|---|---|---|
| Priority: | normal | Milestone: | 0.12.3 |
| Component: | general | Version: | 0.12.2 |
| Severity: | normal | Keywords: | |
| Cc: | Branch: | ||
| Release Notes: | |||
| API Changes: | |||
| Internal Changes: | |||
Description
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)
Change History (5)
by , 14 years ago
| Attachment: | trac.format_datetime.no-unicode-01.patch added |
|---|
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Well…
- 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 , 14 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
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 , 14 years ago
| Owner: | set to |
|---|



I'm not sure if we should do that unconditionally, or have a
strftime()intrac.util.compatfor 2.4 only.