Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 3325 by h.ka...@co-nss.co.jp: 500 internal server error and UnicodeEncodeError exception happens with non-ASCII summary when access to database page of admin.
http://code.google.com/p/reviewboard/issues/detail?id=3325

*** READ THIS BEFORE POSTING!
***
*** You must complete this form in its entirety, or your bug report will be
rejected.
***
*** For customer support, please post to reviewbo...@googlegroups.com
***
*** If you have a patch, please submit it to
http://reviews.reviewboard.org/
***
*** Do not post confidential information in this bug report!


What version are you running?
* Review Board 2.0 RC2
* Django 1.6.3
* Djblets 0.8 RC1

What's the URL of the page containing the problem?
http://MY-SERVER-ADDRESS/admin/db/accounts/reviewrequestvisit/
http://MY-SERVER-ADDRESS/admin/db/reviews/review/

What steps will reproduce the problem?
1. Create some review request with non-ASCII summary text (e.g. Japanese)
2. Login as admin and open database page.
3. Access pages below
    * Review request visits
    * Reviews

What is the expected output? What do you see instead?
Database management page for review requests should be output,
but I got 500 internal server error.
UnicodeEncodeError exception was thrown at then.

What operating system are you using? What browser?
Review board: CentOS 6.5  (Python 2.6.6)
Web browser: Firefox 29.0 running on Windows 7 64bit Japanese

Please provide any additional information below.
Here is Traceback output:

---------------------------------------------------------------------
Traceback (most recent call last):

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/core/handlers/base.py", line 139, in get_response
    response = response.render()

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/response.py", line 105, in render
    self.content = self.rendered_content

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/response.py", line 82, in rendered_content
    content = template.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 140, in render
    return self._render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 134, in _render
    return self.nodelist.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 854, in render_node
    return node.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/loader_tags.py", line 123, in render
    return compiled_parent._render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 134, in _render
    return self.nodelist.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 854, in render_node
    return node.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/loader_tags.py", line 123, in render
    return compiled_parent._render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 134, in _render
    return self.nodelist.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 854, in render_node
    return node.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 854, in render_node
    return node.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 854, in render_node
    return node.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 840, in render
    bit = self.render_node(node, context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 854, in render_node
    return node.render(context)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/template/base.py", line 1196, in render
    _dict = func(*resolved_args, **resolved_kwargs)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/contrib/admin/templatetags/admin_list.py", line 288, in result_list
    'results': list(results(cl))}

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/contrib/admin/templatetags/admin_list.py", line 266, in results
    yield ResultList(None, items_for_result(cl, res, None))

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/contrib/admin/templatetags/admin_list.py", line 258, in __init__
    super(ResultList, self).__init__(*items)

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/contrib/admin/templatetags/admin_list.py", line 214, in items_for_result
    if force_text(result_repr) == '':

File "/usr/lib/python2.6/site-packages/Django-1.6.3-py2.6.egg/django/utils/encoding.py", line 108, in force_text
    s = six.text_type(bytes(s), encoding, errors)

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)

---------------------------------------------------------------------


When the pages output, result of ___str___() in class BaseReviewRequestDetails
is used as summary text.
I think the issue is that __str__() always returns UNICODE string
despite the using Python 2.
According to the Django document
https://docs.djangoproject.com/en/dev/topics/python3/
I tried below and this change fixes this problem and works fine at my server.

---------------------------------------------------------------------
--- reviewboard/reviews/models/base_review_request_details.py.org
+++ reviewboard/reviews/models/base_review_request_details.py
@@ -5,6 +5,7 @@
 from django.db import models
 from django.utils import six
 from django.utils.translation import ugettext_lazy as _
+from django.utils.encoding import python_2_unicode_compatible
 from djblets.db.fields import JSONField

 from reviewboard.diffviewer.models import DiffSet
@@ -13,6 +14,7 @@
 from reviewboard.scmtools.errors import InvalidChangeNumberError

+@python_2_unicode_compatible
 class BaseReviewRequestDetails(models.Model):
     """Base information for a review request and draft.

---------------------------------------------------------------------


--
You received this message because this project is configured to send all issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

--
You received this message because you are subscribed to the Google Groups 
"reviewboard-issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to reviewboard-issues+unsubscr...@googlegroups.com.
To post to this group, send email to reviewboard-issues@googlegroups.com.
Visit this group at http://groups.google.com/group/reviewboard-issues.
For more options, visit https://groups.google.com/d/optout.

Reply via email to