Error with unicode error message

Bug #1168879 reported by Liang Chen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Fix Released
Medium
Liang Chen

Bug Description

Keystone exceptions inherited from keystone.exception.Error can only take acsii message as the message arguments to construct exception instances.

Because keystone.exception.Error inherits from StandardError which in cpython, has a somewhat "buggy" implementation of __unicode__ as following,

static PyObject *
BaseException_unicode(PyBaseExceptionObject *self)
{
    PyObject *out;
    /* issue6108: if __str__ has been overridden in the subclass, unicode()
       should return the message returned by __str__ as used to happen
       before this method was implemented. */
    if (Py_TYPE(self)->tp_str != (reprfunc)BaseException_str) {
        PyObject *str;
        /* Unlike PyObject_Str, tp_str can return unicode (i.e. return the
           equivalent of unicode(e.__str__()) instead of unicode(str(e))). */
        str = Py_TYPE(self)->tp_str((PyObject*)self);
        if (str == NULL)
            return NULL;
        out = PyObject_Unicode(str);
        Py_DECREF(str);
        return out;
    }
    switch (PyTuple_GET_SIZE(self->args)) {
    case 0:
        out = PyUnicode_FromString("");
        break;
    case 1:
        out = PyObject_Unicode(PyTuple_GET_ITEM(self->args, 0));
        break;
    default:
        out = PyObject_Unicode(self->args);
        break;
    }
    return out;
}

thus that whenever keystone.exception.Error.__unicode__ is called, the call will be forwarded to keystone.exception.Error.__str__. And it will cause problem if its error message is unicode string.

Liang Chen (cbjchen)
Changed in keystone:
assignee: nobody → Liang Chen (cbjchen)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystone (master)

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

Changed in keystone:
status: New → In Progress
Liang Chen (cbjchen)
tags: added: grizzly-backport-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to keystone (master)

Reviewed: https://review.openstack.org/26923
Committed: http://github.com/openstack/keystone/commit/d1da173017216a4506d93203a3c1c2fb6bba96b8
Submitter: Jenkins
Branch: master

commit d1da173017216a4506d93203a3c1c2fb6bba96b8
Author: Liang Chen <email address hidden>
Date: Sun Apr 14 22:44:12 2013 +0800

    Enable unicode error message

    Keystone exceptions could only take byte string message as the
    message arguments to construct exception instances because of
    the way its super class StandardError implements __unicode__.
    This patch can also make sure it would not unintentionally remove
    line breaks and indentation in a explicitly given message argument.

    Fixs bug #1168879

    Change-Id: I7916efc87845cfc4dba705e9474125b275affc13

Changed in keystone:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in keystone:
milestone: none → havana-1
status: Fix Committed → Fix Released
Dolph Mathews (dolph)
Changed in keystone:
importance: Undecided → Medium
Thierry Carrez (ttx)
Changed in keystone:
milestone: havana-1 → 2013.2
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.