Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7556 closed defect (fixed)

[Patch] Vote counter problem in trac 0.12

Reported by: Peter Owned by: Ryan J Ollos
Priority: normal Component: VotePlugin
Severity: normal Keywords: vote, unicode
Cc: Trac Release: 0.12


I'm getting an issue with this plugin with trac 0.12. After installing this plugin it does not update the vote counter when clicked on, in my installation. However when I reload the page the vote counter is incremented. When investigating my trac log I found it was generating the following error.

File "build\bdist.win32\egg\tracvote\", line 152, in process_request
    body, title)))
  File "c:\docume~1\lp03\locals~1\temp\1\easy_install-kpxh76\Trac-0.12-py2.7-win32.egg.tmp\trac\web\", line 412, in send
  File "c:\docume~1\lp03\locals~1\temp\1\easy_install-kpxh76\Trac-0.12-py2.7-win32.egg.tmp\trac\web\", line 530, in write
    raise ValueError("Can't send unicode content")
ValueError: Can't send unicode content

On further investigation I think this is related to an API change in 0.12 to refuse taking unicode see

To fix it, for now, I've changed the function process_request, in the file along similar lines as suggested in the above link. i.e. I convert the string passed to req.send to utf-8 if in an unicode format. See new process_request function below...

def process_request(self, req):
        match = self.path_match.match(req.path_info)
        vote, resource = match.groups()
        resource = self.normalise_resource(resource)
        vote = vote == 'up' and +1 or -1
        old_vote = self.get_vote(req, resource)

        if old_vote == vote:
            vote = 0
            self.set_vote(req, resource, 0)
            self.set_vote(req, resource, vote)

        if req.args.get('js'):
            body, title = self.format_votes(resource)
            content = ':'.join(('vote/' + self.image_map[vote][0]),
                      'vote/' + self.image_map[vote][1]),
                                body, title));
            if isinstance(content, unicode): 
 	            content = content.encode('utf-8')                            

Attachments (0)

Change History (7)

comment:1 Changed 8 years ago by Ryan J Ollos

Summary: vote counter problem in trac 0.12 (uni[Patch] Vote counter problem in trac 0.12

Thanks for the patch! I will look at integrating it to a 0.12 branch very soon.

comment:2 Changed 8 years ago by Ryan J Ollos

Reassigning ticket to new maintainer.

comment:3 Changed 8 years ago by Ryan J Ollos

Status: newassigned

I've reproduced the issue with Trac 0.12.1dev-r10015 and confirmed that your patch works. Thank you for the excellent research on this one!

comment:4 Changed 8 years ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

(In [8471]) Changed process_request to convert unicode to utf-8 to account for change in Trac API in 0.12. Thanks to Peter Lawrence for providing a patch. Fixes #7556.

comment:5 Changed 8 years ago by Ryan J Ollos

Confirmed that VotePlugin still works in Trac 0.11.7.

comment:6 Changed 8 years ago by Ryan J Ollos

Added PeterLawrence to list of contributors on project wiki page.

comment:7 Changed 8 years ago by Ryan J Ollos

See also #7519 for what appears to be a similar problem with a different plugin.

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted.

Add Comment

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

Note: See TracTickets for help on using tickets.