Edgewall Software

Ticket #7706 (new defect)

Opened 3 months ago

Last modified 2 months ago

ValueError: too many values to unpack

Reported by: gwk Owned by:
Priority: high Milestone: not applicable
Component: version control Version:
Severity: normal Keywords: multirepos
Cc: gwk.rko@…

Description

How to Reproduce

While doing a GET operation on /changeset/1032:e33a4c091c1e hg-v14, Trac issued an internal error.

I think the problem is some invalid markup in the changeset comment. I tried to hyperlink to a comment within a ticket, and I used the syntax

...according to #507#comment:18 in order to...

While this might be invalid, I would like to get Trac to react gracefully. I would even like to patch it myself but I can't quite understand why it complains "too many values to unpack". If you look at the variable value for lastp below, it does have exactly 2 values, and the failing code is for k, v in lastp. That looks correct to me.

Could someone with more Python powers please teach my why it fails and maybe give a hint how to fix?


Request parameters:

{'new': u'1032:e33a4c091c1e', 'new_path': u'/hg-v14'}

User Agent was: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.0.3) Gecko/2008092510 Ubuntu/8.04 (hardy) Firefox/3.0.3

System Information

Trac 0.12multirepos
Python 2.3.4 (#1, Jan 9 2007, 16:40:09)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-3)]
setuptools 0.6c8
SQLite 3.3.6
pysqlite 2.3.3
Genshi 0.5
Pygments 0.10
Subversion 1.4.6 (r28521)
Mercurial 1.0.1
jQuery: 1.2.3

Python Traceback

Most recent call last:

    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/versioncontrol/templates/changeset.html", line 1, in <Expression u"wiki_to_html(context('changeset', (reponame, changeset.rev)), changeset.message, escape_newlines=True)">
      Code fragment:
         1. <!DOCTYPE html
         2. PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
         3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
         4. <html xmlns="http://www.w3.org/1999/xhtml"
         5. xmlns:py="http://genshi.edgewall.org/"
         6. xmlns:xi="http://www.w3.org/2001/XInclude">
      Local variables:
      Name	Value
      __data__ 	[{'changeset': <tracext.hg.backend.MercurialChangeset object at ...
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/util/compat.py", line 133, in newfunc
      Code fragment:
       128. try:
       129. from functools import partial
       130. except ImportError:
       131. def partial(func_, *args, **kwargs):
       132. def newfunc(*fargs, **fkwargs):
       133. return func_(*(args + fargs), **dict(kwargs, **fkwargs))
       134. newfunc.func = func_
       135. newfunc.args = args
       136. newfunc.keywords = kwargs
       137. try:
       138. newfunc.__name__ = func_.__name__
      Local variables:
      Name	Value
      args 	(<trac.env.Environment object at 0x2a9722e450>,)
      fargs 	(<Context <Resource u"changeset:('hg-v14', '1032:e33a4c091c1e')">>, ...
      fkwargs 	{'escape_newlines': True}
      func_ 	<function format_to_html at 0x2a9720a578>
      kwargs 	{}
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 1107, in format_to_html
      Code fragment:
      1102. return format_to_html(env, context, wikidom, **options)
      1103.  
      1104. def format_to_html(env, context, wikidom, escape_newlines=False):
      1105. if not wikidom:
      1106. return Markup()
      1107. return HtmlFormatter(env, context, wikidom).generate(escape_newlines)
      1108.  
      1109. def format_to_oneliner(env, context, wikidom, shorten=False):
      1110. if not wikidom:
      1111. return Markup()
      1112. return InlineHtmlFormatter(env, context, wikidom).generate(shorten)
      Local variables:
      Name	Value
      context 	<Context <Resource u"changeset:('hg-v14', '1032:e33a4c091c1e')">>
      env 	<trac.env.Environment object at 0x2a9722e450>
      escape_newlines 	True
      wikidom 	u'refactor to introduce portal and portal instance model\n\nrefactor the ...
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 1066, in generate
      Code fragment:
      1061. newlines in the wikidom will be preserved if `escape_newlines` is set.
      1062. """
      1063. # FIXME: compatibility code only for now
      1064. out = StringIO()
      1065. Formatter(self.env, self.context).format(self.wikidom, out,
      1066. escape_newlines)
      1067. return Markup(out.getvalue())
      1068.  
      1069.  
      1070. class InlineHtmlFormatter(object):
      1071. """Format parsed wiki text to inline elements HTML.
      Local variables:
      Name	Value
      escape_newlines 	True
      out 	<StringIO.StringIO instance at 0x2a9bf10a70>
      self 	<trac.wiki.formatter.HtmlFormatter object at 0x2a9ba03d50>
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 862, in format
      Code fragment:
       857. if escape_newlines:
       858. line += ' [[BR]]'
       859. self.in_list_item = False
       860. self.in_quote = False
       861. # Throw a bunch of regexps on the problem
       862. result = re.sub(self.wikiparser.rules, self.replace, line)
       863.  
       864. if not self.in_list_item:
       865. self.close_list()
       866.  
       867. if not self.in_quote:
      Local variables:
      Name	Value
      escape_newlines 	True
      line 	u'refactor the code according to #507#comment:18 in order to introduce ...
      out 	<StringIO.StringIO instance at 0x2a9bf10a70>
      result 	u'refactor to introduce portal and portal instance model <br />'
      self 	<trac.wiki.formatter.Formatter object at 0x2a9ba03750>
      text 	u'refactor to introduce portal and portal instance model\n\nrefactor the ...
    * File "/usr/lib64/python2.3/sre.py", line 143, in sub
      Code fragment:
       138.  
       139. def sub(pattern, repl, string, count=0):
       140. """Return the string obtained by replacing the leftmost
       141. non-overlapping occurrences of the pattern in string by the
       142. replacement repl"""
       143. return _compile(pattern, 0).sub(repl, string, count)
       144.  
       145. def subn(pattern, repl, string, count=0):
       146. """Return a 2-tuple containing (new_string, number).
       147. new_string is the string obtained by replacing the leftmost
       148. non-overlapping occurrences of the pattern in the source
      Local variables:
      Name	Value
      count 	0
      pattern 	<_sre.SRE_Pattern object at 0xcd8e80>
      repl 	<bound method Formatter.replace of <trac.wiki.formatter.Formatter object ...
      string 	u'refactor the code according to #507#comment:18 in order to introduce ...
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 807, in replace
      Code fragment:
       802. internal_handler = getattr(self, '_%s_formatter' % itype)
       803. return internal_handler(match, fullmatch)
       804.  
       805. def replace(self, fullmatch):
       806. """Replace one match with its corresponding expansion"""
       807. replacement = self.handle_match(fullmatch)
       808. if replacement:
       809. return _markup_to_unicode(replacement)
       810.  
       811. def reset(self, source, out=None):
       812. self.source = source
      Local variables:
      Name	Value
      fullmatch 	<_sre.SRE_Match object at 0x12d2800>
      self 	<trac.wiki.formatter.Formatter object at 0x2a9ba03750>
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 803, in handle_match
      Code fragment:
       798. if itype in self.wikiparser.external_handlers:
       799. external_handler = self.wikiparser.external_handlers[itype]
       800. return external_handler(self, match, fullmatch)
       801. else:
       802. internal_handler = getattr(self, '_%s_formatter' % itype)
       803. return internal_handler(match, fullmatch)
       804.  
       805. def replace(self, fullmatch):
       806. """Replace one match with its corresponding expansion"""
       807. replacement = self.handle_match(fullmatch)
       808. if replacement:
      Local variables:
      Name	Value
      fullmatch 	<_sre.SRE_Match object at 0x12d2800>
      internal_handler 	<bound method Formatter._shref_formatter of <trac.wiki.formatter.Formatter ...
      itype 	'shref'
      match 	u'comment:18'
      self 	<trac.wiki.formatter.Formatter object at 0x2a9ba03750>
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 344, in _shref_formatter
      Code fragment:
       339. return text
       340.  
       341. def _shref_formatter(self, match, fullmatch):
       342. ns = fullmatch.group('sns')
       343. target = self._unquote(fullmatch.group('stgt'))
       344. return self._make_link(ns, target, match, match, fullmatch)
       345.  
       346. def _lhref_formatter(self, match, fullmatch):
       347. rel = fullmatch.group('rel')
       348. ns = fullmatch.group('lns')
       349. target = self._unquote(fullmatch.group('ltgt'))
      Local variables:
      Name	Value
      fullmatch 	<_sre.SRE_Match object at 0x12d2800>
      match 	u'comment:18'
      ns 	u'comment'
      self 	<trac.wiki.formatter.Formatter object at 0x2a9ba03750>
      target 	u'18'
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 381, in _make_link
      Code fragment:
       376. def _make_link(self, ns, target, match, label, fullmatch):
       377. # first check for an alias defined in trac.ini
       378. ns = self.env.config['intertrac'].get(ns, ns)
       379. if ns in self.wikiparser.link_resolvers:
       380. return self.wikiparser.link_resolvers[ns](self, ns, target,
       381. escape(label, False))
       382. elif target.startswith('//'):
       383. return self._make_ext_link(ns+':'+target, label)
       384. elif ns == "mailto":
       385. from trac.web.chrome import Chrome
       386. otarget = Chrome(self.env).format_emails(self.context, target)
      Local variables:
      Name	Value
      fullmatch 	<_sre.SRE_Match object at 0x12d2800>
      label 	u'comment:18'
      match 	u'comment:18'
      ns 	u'comment'
      self 	<trac.wiki.formatter.Formatter object at 0x2a9ba03750>
      target 	u'18'
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/ticket/api.py", line 361, in _format_comment_link
      Code fragment:
       356. else:
       357. resource = formatter.resource
       358. cnum = target
       359.  
       360. if resource:
       361. href = "%s#comment:%s" % (formatter.href.ticket(resource.id), cnum)
       362. title = _("Comment %(cnum)s for Ticket #%(id)s", cnum=cnum,
       363. id=resource.id)
       364. return tag.a(label, href=href, title=title)
       365. else:
       366. return label
      Local variables:
      Name	Value
      cnum 	u'18'
      formatter 	<trac.wiki.formatter.Formatter object at 0x2a9ba03750>
      label 	<Markup u'comment:18'>
      ns 	u'comment'
      resource 	<Resource u"changeset:('hg-v14', '1032:e33a4c091c1e')">
      self 	<trac.ticket.api.TicketSystem object at 0x2a999f0f10>
      target 	u'18'
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/web/href.py", line 163, in <lambda>
      Code fragment:
       158.  
       159. return href
       160.  
       161. def __getattr__(self, name):
       162. if not self._derived.has_key(name):
       163. self._derived[name] = lambda *args, **kw: self(name, *args, **kw)
       164. return self._derived[name]
       165.  
       166.  
       167. if __name__ == '__main__':
       168. import doctest, sys
      Local variables:
      Name	Value
      args 	(('hg-v14', '1032:e33a4c091c1e'),)
      kw 	{}
      name 	'ticket'
      self 	<trac.web.href.Href object at 0x2a9ba4a850>
    * File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/web/href.py", line 142, in __call__
      Code fragment:
       137. if lastp and type(lastp) is dict:
       138. for k,v in lastp.items():
       139. add_param(k, v)
       140. args = args[:-1]
       141. elif lastp and type(lastp) in (list, tuple):
       142. for k,v in lastp:
       143. add_param(k, v)
       144. args = args[:-1]
       145.  
       146. # build the path
       147. path = '/'.join([unicode_quote(unicode(arg).strip('/')) for arg in args
      Local variables:
      Name	Value
      add_param 	<function add_param at 0x129e0c8>
      args 	('ticket', ('hg-v14', '1032:e33a4c091c1e'))
      href 	'/trac/SimManager'
      kw 	{}
      lastp 	('hg-v14', '1032:e33a4c091c1e')
      params 	[]
      self 	<trac.web.href.Href object at 0x2a9ba4a850>

File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/versioncontrol/templates/changeset.html", line 1, in <Expression u"wiki_to_html(context('changeset', (reponame, changeset.rev)), changeset.message, escape_newlines=True)">
  <!DOCTYPE html
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/util/compat.py", line 133, in newfunc
  return func_(*(args + fargs), **dict(kwargs, **fkwargs))
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 1107, in format_to_html
  return HtmlFormatter(env, context, wikidom).generate(escape_newlines)
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 1066, in generate
  escape_newlines)
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 862, in format
  result = re.sub(self.wikiparser.rules, self.replace, line)
File "/usr/lib64/python2.3/sre.py", line 143, in sub
  return _compile(pattern, 0).sub(repl, string, count)
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 807, in replace
  replacement = self.handle_match(fullmatch)
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 803, in handle_match
  return internal_handler(match, fullmatch)
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 344, in _shref_formatter
  return self._make_link(ns, target, match, match, fullmatch)
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/wiki/formatter.py", line 381, in _make_link
  escape(label, False))
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/ticket/api.py", line 361, in _format_comment_link
  href = "%s#comment:%s" % (formatter.href.ticket(resource.id), cnum)
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/web/href.py", line 163, in <lambda>
  self._derived[name] = lambda *args, **kw: self(name, *args, **kw)
File "/usr/local/trac-multirepos/lib/python2.3/site-packages/Trac-0.12multirepos-py2.3.egg/trac/web/href.py", line 142, in __call__
  for k,v in lastp:

Attachments

Change History

Changed 3 months ago by gwk.rko@…

  • cc gwk.rko@… added

Changed 3 months ago by cboos

  • keywords multirepos added
  • priority changed from normal to high
  • component changed from general to version control
  • milestone set to not applicable

Interesting bug indeed.

The comment:18 is parsed in isolation, as #123#comment:18 is not valid but comment:18 is, so the formatter assumes the comment is attached to the current resource, here the changeset. Besides the fact that generic comments are not yet implemented (#2035), the problem here is that we use a "composite id" for the changeset resources, in order to encapsulate the extra repository name information.

Composite ids can't be used as such, in a couple of places like this one (e.g. I've seen it when reporting missing permissions).

For the exception itself, nothing mysterious:

for k, v in ('ab', 'def'):
  pass

will give you the same exception when iterating over the second element, as it has more values (here 1-character strings) than the two expected...

Changed 2 months ago by anonymous

?

Add/Change #7706 (ValueError: too many values to unpack)

Author



Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change from (none). Next status will be 'new'
The owner will change from (none) to anonymous. Next status will be 'assigned'
 
Note: See TracTickets for help on using tickets.