#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 |
Description
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\__init__.py", 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\api.py", line 412, in send
self.write(content)
File "c:\docume~1\lp03\locals~1\temp\1\easy_install-kpxh76\Trac-0.12-py2.7-win32.egg.tmp\trac\web\api.py", 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 http://trac.edgewall.org/ticket/8675
To fix it, for now, I've changed the function process_request, in the __init__.py 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):
req.perm.require('VOTE_MODIFY')
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)
else:
self.set_vote(req, resource, vote)
if req.args.get('js'):
body, title = self.format_votes(resource)
content = ':'.join((req.href.chrome('vote/' + self.image_map[vote][0]),
req.href.chrome('vote/' + self.image_map[vote][1]),
body, title));
if isinstance(content, unicode):
content = content.encode('utf-8')
req.send(content);
req.redirect(resource)
Attachments (0)
Change History (7)
comment:1 Changed 15 years ago by
| Summary: | vote counter problem in trac 0.12 (uni → [Patch] Vote counter problem in trac 0.12 |
|---|
comment:3 Changed 15 years ago by
| Status: | new → 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 15 years ago by
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
comment:7 Changed 15 years ago by
See also #7519 for what appears to be a similar problem with a different plugin.



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