Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#7556 closed defect (fixed)

[Patch] Vote counter problem in trac 0.12

Reported by: PeterLawrence Owned by: rjollos
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 4 years ago by rjollos

  • Summary changed from vote counter problem in trac 0.12 (uni to [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 4 years ago by rjollos

Reassigning ticket to new maintainer.

comment:3 Changed 4 years ago by rjollos

  • Status changed from new to assigned

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 4 years ago by rjollos

  • Resolution set to fixed
  • Status changed from assigned to closed

(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 4 years ago by rjollos

Confirmed that VotePlugin still works in Trac 0.11.7.

comment:6 Changed 4 years ago by rjollos

Added PeterLawrence to list of contributors on project wiki page.

comment:7 Changed 4 years ago by rjollos

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

Add Comment

Modify Ticket

as closed .
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from rjollos. Next status will be 'closed'.
The resolution will be deleted. Next status will be 'reopened'.

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

Note: See TracTickets for help on using tickets.