Modify

Opened 5 years ago

Last modified 7 months ago

#5748 new defect

PeerReview search on date fail on non-US locales

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

Description

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:
    1. try:
    2. if not env and env_error:
    3. raise HTTPInternalError(env_error)
    4. try:
    5. dispatcher = RequestDispatcher(env)
    6. dispatcher.dispatch(req)
    7. except RequestDone:
    8. pass
    9. resp = req._response or []
    10. 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:
    1. req.args.get('FORM_TOKEN') != req.form_token:
    2. raise HTTPBadRequest('Missing or invalid form token. '
    3. 'Do you have cookies enabled?')
    4. # Process the request and render the template
    5. resp = chosen_handler.process_request(req)
    6. if resp:
    7. if len(resp) == 2: # Clearsilver
    8. chrome.populate_hdf(req)
    9. template, content_type = \
    10. 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:
    1. finally:
    2. _cache_lock.release()
    3. found = format_regex.match(data_string)
    4. if not found:
    5. raise ValueError("time data did not match format: data=%s fmt=%s" %
    6. (data_string, format))
    7. if len(data_string) != found.end():
    8. raise ValueError("unconverted data remains: %s" %
    9. data_string[found.end():])
    10. year = 1900
    11. 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')

Attachments (0)

Change History (2)

comment:1 Changed 3 years ago by andersm

  • Owner changed from mikechml to andersm

comment:2 Changed 7 months 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.

Add Comment

Modify Ticket

Action
as new .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.