Quantum xml doesn't work with unicode

Bug #1160644 reported by Alex Xu
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
High
Alex Xu

Bug Description

When enable Chinese translation file and raise an exception that translated by Chinese will get exception as below:

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/eventlet/wsgi.py", line 382, in handle_one_response
    result = self.application(self.environ, start_response)
  File "/usr/lib/python2.7/dist-packages/paste/urlmap.py", line 203, in __call__
    return app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/python_keystoneclient-0.2.2.21.g92bf8a7-py2.7.egg/keystoneclient/middleware/auth_token.py", line 348, in __call__
    return self.app(env, start_response)
  File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 144, in __call__
    return resp(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 144, in __call__
    return resp(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/routes/middleware.py", line 131, in __call__
    response = self.app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 144, in __call__
    return resp(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 144, in __call__
    return resp(environ, start_response)
  File "/usr/lib/python2.7/dist-packages/routes/middleware.py", line 131, in __call__
    response = self.app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 144, in __call__
    return resp(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 130, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 195, in call_func
    return self.func(req, *args, **kwargs)
  File "/home/soulxu/work-code/openstack/quantum/quantum/api/v2/resource.py", line 86, in resource
    body = serializer.serialize({'QuantumError': str(e)})
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-4: ordinal not in range(128)

How to reproduce:
1. initialize or update template to chinese template

initialize:
python ./setup.py init_catalog -l zh_CN -i quantum/locale/quantum.pot -o quantum/locale/zh_CN/LC_MESSAGES/quantum.po

update:
python ./setup.py update_catalog -l zh_CN -i quantum/locale/quantum.pot -o quantum/locale/zh_CN/LC_MESSAGES/quantum.po

2. Translate a message of exception that you want to raise. There is chinese for test '中文中文'

3. compile catalog
python ./setup.py compile_catalog --directory quantum/locale --locale zh_CN

4. cp quantum/locale/zh_CN/LC_MESSAGES/quantum.mo /usr/share/locale/zh_CN/LC_MESSAGES/

5. running quantum with env varables: LANGUAGE=zh_CN:zh LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8

6. then use quantum cli tools to raise the error that you have translated.

Tags: quantum-core
Alex Xu (xuhj)
Changed in quantum:
assignee: nobody → Alex Xu (xuhj)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to quantum (master)

Fix proposed to branch: master
Review: https://review.openstack.org/25482

Changed in quantum:
status: New → In Progress
Changed in quantum:
importance: Undecided → High
milestone: none → havana-1
Alex Xu (xuhj)
description: updated
description: updated
description: updated
Revision history for this message
Alex Xu (xuhj) wrote :

I can't reproduce this before. That was because I run quantum with eclipse, eclipse should have custom site.py. That change the default encode to utf-8, so I never can reproduce this bug. After I run quantum in console directly, this bug was reproduced.

If you can't reproduce this problem, please check your default encode by:

In [13]: import sys

In [14]: sys.getdefaultencoding()
Out[14]: 'ascii'

And ensure the output was 'ascii'

tags: added: quantum-core
tags: added: grizzly-backport-potential
Thierry Carrez (ttx)
Changed in quantum:
milestone: havana-1 → grizzly-rc3
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to quantum (master)

Reviewed: https://review.openstack.org/25482
Committed: http://github.com/openstack/quantum/commit/26dca9ff02dc9eb9b431ea66ec60fb828b4ae0a5
Submitter: Jenkins
Branch: master

commit 26dca9ff02dc9eb9b431ea66ec60fb828b4ae0a5
Author: He Jie Xu <email address hidden>
Date: Wed Mar 27 07:42:20 2013 +0800

    Return unicode for object in json and xml serializer

    Fix bug 1160644
    Fix bug 1119790

    When try to serialize an exception object as json, it failed
    with 'ValueError: Circular reference detected' that is same error
    as bug 119790. So this patch fixes bug 119790 too.

    Change-Id: I0da2616f4ec59da31be054b8be2f7a140f59d63a

Changed in quantum:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to quantum (milestone-proposed)

Fix proposed to branch: milestone-proposed
Review: https://review.openstack.org/25922

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to quantum (milestone-proposed)

Reviewed: https://review.openstack.org/25922
Committed: http://github.com/openstack/quantum/commit/46af52f24de13ce535a81573210d1a4f1bd93d96
Submitter: Jenkins
Branch: milestone-proposed

commit 46af52f24de13ce535a81573210d1a4f1bd93d96
Author: He Jie Xu <email address hidden>
Date: Wed Mar 27 07:42:20 2013 +0800

    Return unicode for object in json and xml serializer

    Fix bug 1160644
    Fix bug 1119790

    When try to serialize an exception object as json, it failed
    with 'ValueError: Circular reference detected' that is same error
    as bug 119790. So this patch fixes bug 119790 too.

    Change-Id: I0da2616f4ec59da31be054b8be2f7a140f59d63a
    (cherry picked from commit 26dca9ff02dc9eb9b431ea66ec60fb828b4ae0a5)

Changed in quantum:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in quantum:
milestone: grizzly-rc3 → 2013.1
Alan Pevec (apevec)
tags: removed: grizzly-backport-potential
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.