Error with unicode error message

Bug #1168879 reported by Liang Chen on 2013-04-14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
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);
        return out;
    switch (PyTuple_GET_SIZE(self->args)) {
    case 0:
        out = PyUnicode_FromString("");
    case 1:
        out = PyObject_Unicode(PyTuple_GET_ITEM(self->args, 0));
        out = PyObject_Unicode(self->args);
    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) on 2013-04-14
Changed in keystone:
assignee: nobody → Liang Chen (cbjchen)

Fix proposed to branch: master

Changed in keystone:
status: New → In Progress
Liang Chen (cbjchen) on 2013-04-25
tags: added: grizzly-backport-potential

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) on 2013-05-29
Changed in keystone:
milestone: none → havana-1
status: Fix Committed → Fix Released
Dolph Mathews (dolph) on 2013-09-19
Changed in keystone:
importance: Undecided → Medium
Thierry Carrez (ttx) on 2013-10-17
Changed in keystone:
milestone: havana-1 → 2013.2
Alan Pevec (apevec) on 2014-03-30
tags: removed: grizzly-backport-potential
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers