Opened 15 years ago

Closed 8 years ago

Last modified 8 years ago

#5748 closed defect (fixed)

PeerReview search on date fail on non-US locales — at Version 4

Reported by: isaac.to@… Owned by: Marc
Priority: normal Component: PeerReviewPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description (last modified by Ryan J Ollos)

I'm running the current subversion version (r6459) of the 2.2-dev branch of the plugin, over a 0.11.5 trac. I see the following error when I perform a "search code reviews" and specify a date for "Reviews after date":

 Most recent call last:

    * File "/home/arbit/opt/2/x86_64/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/main.py", line 444, in _dispatch_request
      Code fragment:
       439. try:
       440. if not env and env_error:
       441. raise HTTPInternalError(env_error)
       442. try:
       443. dispatcher = RequestDispatcher(env)
       444. dispatcher.dispatch(req)
       445. except RequestDone:
       446. pass
       447. resp = req._response or []
       448.  
       449. except HTTPException, e:
      Local variables:
      Name	Value
      after 	[u' except RequestDone:', u' pass', u' resp = ...
      before 	[u' try:', u' if not env and env_error:', u' raise ...
      dispatcher 	<trac.web.main.RequestDispatcher object at 0xc985c50>
      e 	ValueError(u'time data did not match format: data=08/01/09 fmt=%x',)
      env 	<trac.env.Environment object at 0xc660250>
      env_error 	None
      exc_info 	(<type 'exceptions.ValueError'>, ValueError(u'time data did not match ...
      filename 	'/home/arbit/opt/2/x86_64/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg ...
      frames 	[{'function': '_dispatch_request', 'lines_before': [u' try:', u' ...
      has_admin 	True
      line 	u' dispatcher.dispatch(req)'
      lineno 	443
      message 	u'ValueError: time data did not match format: data=08/01/09 fmt=%x'
      req 	<Request "POST u'/peerReviewSearch'">
      resp 	[]
      tb 	<traceback object at 0xd16a0e0>
      tb_hide 	None
      traceback 	u'Traceback (most recent call last):\n File ...
    * File "/home/arbit/opt/2/x86_64/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/main.py", line 205, in dispatch
      Code fragment:
       200. req.args.get('__FORM_TOKEN') != req.form_token:
       201. raise HTTPBadRequest('Missing or invalid form token. '
       202. 'Do you have cookies enabled?')
       203.  
       204. # Process the request and render the template
       205. resp = chosen_handler.process_request(req)
       206. if resp:
       207. if len(resp) == 2: # Clearsilver
       208. chrome.populate_hdf(req)
       209. template, content_type = \
       210. self._post_process_request(req, *resp)
      Local variables:
      Name	Value
      chosen_handler 	<codereview.peerReviewSearch.UserbaseModule object at 0xc98d090>
      chrome 	<trac.web.chrome.Chrome object at 0xc985a10>
      ctype 	'application/x-www-form-urlencoded'
      err 	(<type 'exceptions.ValueError'>, ValueError(u'time data did not match ...
      handler 	<codereview.peerReviewSearch.UserbaseModule object at 0xc98d090>
      options 	{}
      req 	<Request "POST u'/peerReviewSearch'">
      self 	<trac.web.main.RequestDispatcher object at 0xc985c50>
    * File "build/bdist.linux-i686/egg/codereview/peerReviewSearch.py", line 52, in process_request
      Local variables:
      Name	Value
      data 	{'searchValues_author': u'Select...', 'searchValues_day': u'01', ...
      req 	<Request "POST u'/peerReviewSearch'">
      self 	<codereview.peerReviewSearch.UserbaseModule object at 0xc98d090>
    * File "build/bdist.linux-i686/egg/codereview/peerReviewSearch.py", line 138, in performSearch
      Local variables:
      Name	Value
      author 	u'Select...'
      crStruct 	<codereview.CodeReviewStruct.CodeReviewStruct object at 0xd0ff4d0>
      data 	{'searchValues_author': u'Select...', 'searchValues_day': u'01', ...
      day 	u'01'
      fromdate 	'-1'
      month 	u'08'
      name 	u''
      req 	<Request "POST u'/peerReviewSearch'">
      self 	<codereview.peerReviewSearch.UserbaseModule object at 0xc98d090>
      status 	u'Select...'
      year 	u'2009'
    * File "/home/arbit/opt/2/x86_64/lib/python2.5/_strptime.py", line 330, in strptime
      Code fragment:
       325. finally:
       326. _cache_lock.release()
       327. found = format_regex.match(data_string)
       328. if not found:
       329. raise ValueError("time data did not match format: data=%s fmt=%s" %
       330. (data_string, format))
       331. if len(data_string) != found.end():
       332. raise ValueError("unconverted data remains: %s" %
       333. data_string[found.end():])
       334. year = 1900
       335. month = day = 1
      Local variables:
      Name	Value
      data_string 	u'08/01/09'
      format 	'%x'
      format_regex 	<_sre.SRE_Pattern object at 0xcc98a20>
      found 	None
      locale_time 	<_strptime.LocaleTime object at 0xd00e350>

File "/home/arbit/opt/2/x86_64/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/main.py", line 444, in _dispatch_request
  dispatcher.dispatch(req)
File "/home/arbit/opt/2/x86_64/lib/python2.5/site-packages/Trac-0.11.5-py2.5.egg/trac/web/main.py", line 205, in dispatch
  resp = chosen_handler.process_request(req)
File "build/bdist.linux-i686/egg/codereview/peerReviewSearch.py", line 52, in process_requestFile "build/bdist.linux-i686/egg/codereview/peerReviewSearch.py", line 138, in performSearchFile "/home/arbit/opt/2/x86_64/lib/python2.5/_strptime.py", line 330, in strptime
  (data_string, format))

It is clear that the culprit is the following line in the peerReviewSearch function:

t = time.strptime(month + '/' + day + '/' + year[2] + year[3], '%x')

This does not work in all locale, since "%x" means the following, as described in the manual of the time module:

%x: Locale’s appropriate date representation

Since the date string constructed by the program is always in a particular format, I suggest changing it to:

t = time.strptime(month + '/' + day + '/' + year[2] + year[3], '%m/%d/%y')

Change History (4)

comment:1 Changed 13 years ago by Marc

Owner: changed from mikechml to Marc

comment:2 Changed 10 years ago by anonymous

I ran into this issue as well.

Regarding changing the strptime date format from '%x' to '%m/%d/%y' ... This fixed it for me!

I recommend applying this patch.

comment:3 Changed 8 years ago by Cinc-th

Resolution: fixed
Status: newclosed

In 15171:

Fix for date problem for non-US locales. Applied proposed fix. Some minor cleanups while at it.

Fixes #5748

comment:4 Changed 8 years ago by Ryan J Ollos

Description: modified (diff)
Note: See TracTickets for help on using tickets.