#10505 closed defect (fixed)
KeyError: 's'
Reported by: | lauril | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.0 |
Component: | i18n | Version: | 0.13dev |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
More robust date parsing |
||
API Changes: | |||
Internal Changes: |
Description
How to Reproduce
While doing a POST operation on /milestone
, Trac issued an internal error.
(please provide additional details here)
Request parameters:
{'__FORM_TOKEN': u'835642a9d0422462ff43283e', 'action': u'edit', 'completed': u'on', 'completeddate': u'Fed 29, 2012 4:00:00 PM', 'description': u"'''Syfte:'''\r\nEtt f\xf6rsta steg f\xf6r att utv\xe4rdera om ", 'due': u'on', 'duedate': u'Dec 17, 2011 6:00:00 PM', 'id': u'', 'name': u'Akvik traffik plats'}
User agent: Mozilla/5.0 (Ubuntu; X11; Linux x86_64; rv:8.0) Gecko/20100101 Firefox/8.0
System Information
Trac | 0.13dev-r10883
|
Babel | 0.9.4
|
Docutils | 0.6
|
Genshi | 0.6
|
mod_wsgi | 3.2 (WSGIProcessGroup WSGIApplicationGroup %{GLOBAL})
|
MySQL | server: "5.1.52", client: "5.1.52", thread-safe: 0
|
MySQLdb | 1.2.3c1
|
Pygments | 1.1.1
|
Python | 2.6.5 (r265:79063, Jun 25 2011, 08:36:25) [GCC 4.4.4 20100726 (Red Hat 4.4.4-13)]
|
setuptools | 0.6
|
Subversion | 1.6.11 (r934486)
|
jQuery | 1.5.1
|
Enabled Plugins
NavAdd | 0.1
|
Trac-jsGantt | 0.9-r10876
|
TracAccountManager | 0.3.2
|
TracListOfWikiPagesMacro | 0.4
|
TracSumStats | 0.9.0
|
WikiTableMacro | 0.1-r10442
|
Python Traceback
Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/Trac-0.13dev_r10883-py2.6.egg/trac/web/main.py", line 478, in _dispatch_request dispatcher.dispatch(req) File "/usr/lib/python2.6/site-packages/Trac-0.13dev_r10883-py2.6.egg/trac/web/main.py", line 198, in dispatch resp = chosen_handler.process_request(req) File "/usr/lib/python2.6/site-packages/Trac-0.13dev_r10883-py2.6.egg/trac/ticket/roadmap.py", line 679, in process_request return self._do_save(req, milestone) File "/usr/lib/python2.6/site-packages/Trac-0.13dev_r10883-py2.6.egg/trac/ticket/roadmap.py", line 754, in _do_save hint='datetime') if completed else None File "/usr/lib/python2.6/site-packages/Trac-0.13dev_r10883-py2.6.egg/trac/util/datefmt.py", line 594, in user_time return func(*args, **kwargs) File "/usr/lib/python2.6/site-packages/Trac-0.13dev_r10883-py2.6.egg/trac/util/datefmt.py", line 346, in parse_date dt = _i18n_parse_date(text, tzinfo, locale) File "/usr/lib/python2.6/site-packages/Trac-0.13dev_r10883-py2.6.egg/trac/util/datefmt.py", line 459, in _i18n_parse_date month_names, tzinfo) File "/usr/lib/python2.6/site-packages/Trac-0.13dev_r10883-py2.6.egg/trac/util/datefmt.py", line 478, in _i18n_parse_date_0 matches.insert(order['s'], 0) KeyError: 's'
Attachments (0)
Change History (5)
comment:1 by , 13 years ago
Component: | general → i18n |
---|---|
Milestone: | → 0.13 |
Owner: | set to |
comment:2 by , 13 years ago
It's easy to reproduce:
>>> from trac.util.datefmt import * >>> parse_date("Fed 29, 2012 4:00:00 PM", locale='en_US') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "trac\util\datefmt.py", line 346, in parse_date dt = _i18n_parse_date(text, tzinfo, locale) File "trac\util\datefmt.py", line 459, in _i18n_parse_date month_names, tzinfo) File "trac\util\datefmt.py", line 478, in _i18n_parse_date_0 matches.insert(order['s'], 0) KeyError: 's'
Adding a print(repr((matches, order)))
just before the order['s']
line shows:
(['29', '2012', '4', '00', '00'], {'M': 1, 'd': 0, 'h': 3, 'm': 4, 's': 5, 'y': 2}) (['29', '2012', '4', '00', '00'], {'y': 2, 'M': 1, 'd': 0})
which suggests that for a locale there can be a date+time and date only patterns.
The if len(matches) == 5
check (which I suspect is there to cope with a date+time spec where the seconds are missing) will not work for date only patterns. Note that here we have seconds, but as "Fed" is not recognized as a month, the date+time pattern will not match and the date only is then tried and fails. There are also other ways to trigger the error, like with parse_date("2012 29 4:00 Feb", locale='en_US')
.
Suggested fix:
-
trac/util/datefmt.py
474 474 del matches[idx] 475 475 break 476 476 477 if len(matches) == 5: 477 # for date+time patterns, use 0 seconds if seconds are missing 478 if len(matches) == 5 and 's' in order: 478 479 matches.insert(order['s'], 0) 479 480 480 481 values = {}
Leaving final fix and say on the matter (and extra unit-tests) for Jun ;-)
comment:4 by , 13 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Fixed in [10891] and added unit tests. Thanks for the report.
comment:5 by , 12 years ago
Release Notes: | modified (diff) |
---|
Mmh… No idea what what's wrong here. Jun?