Edgewall Software
Modify

Opened 21 months ago

Closed 17 months ago

Last modified 17 months ago

#13495 closed defect (fixed)

TypeError raised when viewing mercurial changeset

Reported by: Jun Omae Owned by: Jun Omae
Priority: normal Milestone: 1.5.4
Component: version control Version: 1.5.3
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Fixed TypeError raised from changeset view when non-default property renderer is used and the quality is 1.

API Changes:
Internal Changes:

Description

I encountered the following error while porting mercurial plugin to Python 3:

Traceback (most recent call last):
  File "/vol/src/tracdev/git/trac/web/main.py", line 610, in dispatch_request
    dispatcher.dispatch(req)
  File "/vol/src/tracdev/git/trac/web/main.py", line 302, in dispatch
    raise e
  File "/vol/src/tracdev/git/trac/web/main.py", line 248, in dispatch
    resp = chosen_handler.process_request(req)
  File "/vol/src/tracdev/git/trac/versioncontrol/web_ui/changeset.py", line 349, in process_request
    self._render_html(req, repos, chgset, restricted, data)
  File "/vol/src/tracdev/git/trac/versioncontrol/web_ui/changeset.py", line 424, in _render_html
    data['properties'] = browser.render_properties('revprop', context,
  File "/vol/src/tracdev/git/trac/versioncontrol/web_ui/browser.py", line 761, in render_properties
    [self.render_property(name, mode, context, props)
  File "/vol/src/tracdev/git/trac/versioncontrol/web_ui/browser.py", line 761, in <listcomp>
    [self.render_property(name, mode, context, props)
  File "/vol/src/tracdev/git/trac/versioncontrol/web_ui/browser.py", line 774, in render_property
    candidates.sort(reverse=True)
TypeError: '<' not supported between instances of 'DefaultPropertyRenderer' and 'HgDefaultPropertyRenderer'

Fix:

  • trac/versioncontrol/web_ui/browser.py

    diff --git a/trac/versioncontrol/web_ui/browser.py b/trac/versioncontrol/web_ui/browser.py
    index 98a3d6248..9df4bc7af 100644
    a b class BrowserModule(Component):  
    770770            quality = renderer.match_property(name, mode)
    771771            if quality > 0:
    772772                candidates.append((quality, renderer))
    773         candidates.sort(reverse=True)
     773        candidates.sort(reverse=True, key=lambda c: c[0])
    774774        for (quality, renderer) in candidates:
    775775            try:
    776776                rendered = renderer.render_property(name, mode, context, props)

Work around in mercurial plugin:

     def match_property(self, name, mode):
-       return name.startswith('hg-') and mode == 'revprop' and 1 or 0
+       return name.startswith('hg-') and mode == 'revprop' and 2 or 0

Attachments (0)

Change History (3)

comment:1 by Jun Omae, 21 months ago

Reconsidering, I think non-default renderer should be preferred with same quality.

  • trac/versioncontrol/web_ui/browser.py

    diff --git a/trac/versioncontrol/web_ui/browser.py b/trac/versioncontrol/web_ui/browser.py
    index 98a3d6248..265f52726 100644
    a b class BrowserModule(Component):  
    770770            quality = renderer.match_property(name, mode)
    771771            if quality > 0:
    772772                candidates.append((quality, renderer))
    773         candidates.sort(reverse=True)
     773        def keyfunc(candidate):
     774            quality, renderer = candidate
     775            # Prefer non-default renderer if the renderers have same quality
     776            return quality, \
     777                   0 if isinstance(renderer, DefaultPropertyRenderer) else 1, \
     778                   renderer.__class__.__name__
     779        candidates.sort(reverse=True, key=keyfunc)
    774780        for (quality, renderer) in candidates:
    775781            try:
    776782                rendered = renderer.render_property(name, mode, context, props)

comment:2 by Jun Omae, 17 months ago

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

Fixed in [17620].

comment:3 by Jun Omae, 17 months ago

Owner: set to Jun Omae

Modify Ticket

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