Edgewall Software
Modify

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#12682 closed defect (fixed)

TypeError: expected string or buffer

Reported by: Ryan J Ollos Owned by: Ryan J Ollos
Priority: normal Milestone: 1.0.14
Component: search system Version:
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Fixed TypeError when repeated q argument to SearchModule.

API Changes:
Internal Changes:

Description

2017-02-07 16:14:11,290 Trac[main] ERROR: Internal Server Error: <RequestWithSession "GET '/search?q=aHR0cHM6Ly90cmFjLWhhY2tzLm9yZy9uZXd0aWNrZXQ%3D&____pgfa=aHR0cHM6Ly90cmFjLWhhY2tzLm9yZy9zZWFyY2g%253D&q='">, referrer 'https://trac-hacks.org/newticket'
Traceback (most recent call last):
  File "/srv/trac-hacks.org/pve/local/lib/python2.7/site-packages/trac/web/main.py", line 562, in _dispatch_request
    dispatcher.dispatch(req)
  File "/srv/trac-hacks.org/pve/local/lib/python2.7/site-packages/trac/web/main.py", line 249, in dispatch
    resp = chosen_handler.process_request(req)
  File "/srv/trac-hacks.org/pve/local/lib/python2.7/site-packages/trac/search/web_ui.py", line 100, in process_request
    data['quickjump'] = self._check_quickjump(req, query)
  File "/srv/trac-hacks.org/pve/local/lib/python2.7/site-packages/trac/search/web_ui.py", line 169, in _check_quickjump
    link = find_element(extract_link(self.env, context, kwd), 'href')
  File "/srv/trac-hacks.org/pve/local/lib/python2.7/site-packages/trac/wiki/formatter.py", line 1598, in extract_link
    return LinkFormatter(env, context).match(wikidom)
  File "/srv/trac-hacks.org/pve/local/lib/python2.7/site-packages/trac/wiki/formatter.py", line 1514, in match
    match = re.match(self.wikiparser.rules, wikitext)
  File "/srv/trac-hacks.org/pve/lib/python2.7/re.py", line 141, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or buffer

This can be reproduced with /search?q=a&q=.

Attachments (0)

Change History (8)

comment:1 by Ryan J Ollos, 4 years ago

Release Notes: modified (diff)
Resolution: fixed
Status: assignedclosed

Committed to 1.0-stable in r15512, merged to 1.2-stable in r15513, merged to trunk in r15514.

comment:2 by Christian Boos, 4 years ago

How many times do we actually want all occurrences of a repeated parameter? col in /query, a few others maybe, but for the most case, we expect scalar values. Can't we make getfirst the default (i.e. alias get to getfirst), and use getall explicitly when we expect an array?

comment:3 by Ryan J Ollos, 4 years ago

I had a similar thought a few hours after committing the change. The only downside I see is that it's an API change that plugins would need to immediately adapt to.

comment:4 by Ryan J Ollos, 4 years ago

I was also considering adding a method to retrieve a binary integer, to handle the common pattern of '0' and '1' in the args: req.args.getint('asc', 1, min=0, max=1)req.args.getbint('asc', 1).

comment:5 by Ryan J Ollos, 4 years ago

Another traceback found today that would be fixed by making get alias getfirst:

2017-02-09 17:09:23,634 Trac[main] ERROR: Internal Server Error: <RequestWithSession "GET '/query?milestone=1.4.3&group=status&page=4&desc=1&order=component&row=description&coi=1494&npp=2&p=0&pp=0&mid=9&ep=2&du=https%3a//bugs.jquery.com/query?milestone=1.4.3&group=status&page=4&...=E71449111ACF9D8A165B8722E2317E7E'">, referrer 'https://bugs.jquery.com/query?milestone=1.4.3&group=status&page=4&desc=1&order=component&row=description&coi=1494&npp=2&p=0&pp=0&mid=9&ep=2&du=https%3a//cnc-printers.ru%2Fuser%2FNidaHeist1%2F'
Traceback (most recent call last):
  File "/var/www/bugs.jquery.com/private/pve/local/lib/python2.7/site-packages/trac/web/main.py", line 562, in _dispatch_request
    dispatcher.dispatch(req)
  File "/var/www/bugs.jquery.com/private/pve/local/lib/python2.7/site-packages/trac/web/main.py", line 249, in dispatch
    resp = chosen_handler.process_request(req)
  File "/var/www/bugs.jquery.com/private/pve/local/lib/python2.7/site-packages/trac/ticket/query.py", line 983, in process_request
    max)
  File "/var/www/bugs.jquery.com/private/pve/local/lib/python2.7/site-packages/trac/ticket/query.py", line 91, in __init__
    self.page = int(page)
TypeError: int() argument must be a string or a number, not 'list'

comment:6 by Christian Boos, 4 years ago

Yes, in the long run I think that would pay off. Anyway, the current API of Request.get() is not very Pythonic, returning either a scalar or a vector, depending on what was given. As we have no real control over what's given, it can really be one or the other anytime.

Regarding getbint, yes, but maybe getbinary instead?

comment:7 by Ryan J Ollos, 4 years ago

Created #12684.

comment:8 by Ryan J Ollos, 4 years ago

Addressed comment:5 on 1.2-stable in r15572, merged to trunk in r15573. I'll refactor this in #12684.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Ryan J Ollos 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.