VersionedObject.__repr__ should return encoded string

Bug #1514325 reported by Liang Chen on 2015-11-09
52
This bug affects 7 people
Affects Status Importance Assigned to Milestone
Cinder
Undecided
Liang Chen
oslo.versionedobjects
Undecided
Liang Chen
cinder (Ubuntu)
Medium
Liang Chen

Bug Description

[Impact]

 * Cinder snapshot display-description cannot contain non-ascii characters.

[Test Case]

 * cinder create 1
 * cinder snapshot-create --display-description "中文" <the volume ID>

[Regression Potential]

 * None

The following error is reported when creating a volume snapshot with non-ascii display-description, e.g. cinder snapshot-create --display-description "中文" my-2nd-volume.

2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher [req-81f48a02-b1ef-4aae-9e22-ac2ce1c75b2f 16818cbff07548889da69bf526558d97 7aac0111a39741f59513c05b2d83dd70 - - -] Exception during message handling: 'ascii' codec can't encode characters in position 111-117: ordinal not in range(128)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher Traceback (most recent call last):
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 142, in _dispatch_and_reply
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher executor_callback))
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 186, in _dispatch
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher executor_callback)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 129, in _do_dispatch
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher result = func(ctxt, **new_args)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher File "/usr/lib/python2.7/dist-packages/osprofiler/profiler.py", line 102, in wrapper
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher info["function"]["kwargs"] = str(kwargs)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher UnicodeEncodeError: 'ascii' codec can't encode characters in position 111-117: ordinal not in range(128)
2015-11-09 05:55:50.995 29937 ERROR oslo_messaging.rpc.dispatcher

Root cause is that profiler tries to get a string representation of the arguments (cinder.objects.snapshot.Snapshot) of the snapshot-create cinder-volume service api. As a result, VersionedObject.__repr__ is called to produce such a string representation with an attribute (display-description) containing non-ascii characters, thus returning an unicode object. However when __repr__ returns an unicode object, it's expected that the the returned string can be encoded by default encoding scheme which is ascii in general [1][2]. So __repr__ needs to make sure any unicode string it's going to return are properly encoded.

[1] trying to encode the returned string when it's an unicode object
https://github.com/python/cpython/blob/2.7/Objects/object.c#L387

[2] if encoding arg is left null, default encoding will be used
https://github.com/python/cpython/blob/2.7/Objects/unicodeobject.c#L1355

Tags: sts Edit Tag help

Related branches

Liang Chen (cbjchen) on 2015-11-09
Changed in oslo.versionedobjects:
assignee: nobody → Liang Chen (cbjchen)
description: updated
Liang Chen (cbjchen) wrote :
Changed in oslo.versionedobjects:
status: New → In Progress
Liang Chen (cbjchen) on 2015-11-10
Changed in oslo.versionedobjects:
status: In Progress → Fix Committed
Liang Chen (cbjchen) on 2015-11-10
tags: added: sts
Changed in oslo.versionedobjects:
milestone: none → 0.13.0
status: Fix Committed → Fix Released
Liang Chen (cbjchen) on 2015-11-18
Changed in cinder:
assignee: nobody → Liang Chen (cbjchen)
status: New → In Progress
Liang Chen (cbjchen) wrote :

Fix proposed to branch: stable/liberty at https://review.openstack.org/#/c/246758/

Liang Chen (cbjchen) on 2015-12-25
description: updated
Changed in cinder (Ubuntu):
status: New → In Progress
assignee: nobody → Liang Chen (cbjchen)
Mathew Hodson (mhodson) on 2015-12-31
Changed in cinder (Ubuntu):
importance: Undecided → Medium

Change abandoned by Eric Harney (<email address hidden>) on branch: stable/kilo
Review: https://review.openstack.org/246772
Reason: -2 in November, and I agree with that, so cleaning this one out of the queue.

James Page (james-page) wrote :

Accepted into stable/liberty a while back, so Ubuntu + UCA with >= liberty will now have this fix.

Marking 'Fix Released'

Changed in cinder (Ubuntu):
status: In Progress → Fix Released
Matt Riedemann (mriedem) on 2016-09-13
Changed in cinder:
status: In Progress → Invalid
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers