Keystone Cannot Translate the REST API message returned from exception.py

Bug #1179425 reported by hufali
14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Fix Released
Wishlist
David Jia

Bug Description

The doc string in exception.py of Keystone will be returned with __doc__ method, but cannot realize the internationalization.

/v2.0/tokens
{
    "error": {
        "message": "Expecting to find username or userId in passwordCredentials. The server could not comply with the request since it is either malformed or otherwise incorrect. The client is assumed to be in error.",
        "code": 400,
        "title": "Bad Request"
    }
}
{
    "error": {
        "message": "The request you have made requires authentication.",
        "code": 401,
        "title": "Not Authorized"
    }
}
{
    "error": {
        "message": "Invalid user / password",
        "code": 401,
        "title": "Not Authorized"
    }
}
The message in error which should be translated is returned from the doc string in excetpion.py of Keystone.

hufali (hufali87)
description: updated
description: updated
description: updated
David Jia (jiataotj)
Changed in keystone:
assignee: nobody → David Jia (jiataotj)
Revision history for this message
David Jia (jiataotj) wrote :

in keystone exception.py, there are a lot of doc string which are used as REST API return messages, those doc string can't be translated to other language, because python doesn't support to directly translate the doc string in the program.Then those messages will be returned as hardcode, it doesn't make sense, since other REST API return messages can be translated,so I think we need modify the exception.py to support i18n

Revision history for this message
David Jia (jiataotj) wrote :

As below codes shows,in keystone exception.py, doc string are used as REST API return message

class Error(StandardError):
    """Base error class.

    Child classes should define an HTTP status code, title, and a doc string.

    """
    code = None
    title = None

    def __init__(self, message=None, **kwargs):
        """Use the doc string as the error message by default."""

        try:
            message = self._build_message(message, **kwargs)
        except KeyError as e:
            # if you see this warning in your logs, please raise a bug report
            if _FATAL_EXCEPTION_FORMAT_ERRORS:
                raise e
            else:
                LOG.warning('missing exception kwargs (programmer error)')
                message = self.__doc__

        super(Error, self).__init__(message)
------------------------------------------------------------------------------------------------------------------------------------------------------
Below is a sample class whose doc string will be returnd when the error exist

class ValidationSizeError(Error):
    """Request attribute %(attribute)s must be less than or equal to %(size)i.

    The server could not comply with the request because the attribute
    size is invalid (too large).

    The client is assumed to be in error.

    """
    code = 400
    title = 'Bad Request'

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

we can't wrap doc string using _() to translate them to implement i18n support, we can use message as class variable to replace using doc string to enable return message translation

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/29367

Changed in keystone:
assignee: David Jia (jiataotj) → Dolph Mathews (dolph)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

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

Changed in keystone:
assignee: Dolph Mathews (dolph) → David Jia (jiataotj)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

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

Dolph Mathews (dolph)
Changed in keystone:
importance: Undecided → Wishlist
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to keystone (master)

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

commit f976bbe697002367ff00a0588a3181fd42008e1c
Author: jiataotj <email address hidden>
Date: Fri May 31 00:18:28 2013 +0800

    Implement exception module i18n support

    The doc string in exception.py of Keystone will be
    returned with __doc__ method, but cannot realize the
    internationalization.Change exception module to enable
    i18n support.

    Changes in the patch are:
    1, useing class variable msg_fmt to replace class __doc__
    2, modify wsgi.render_exception function using unicode
    function to replace str function
    3, modify/add UT test cases

    Fixes: bug # 1179425

    Change-Id: I75c1229c905a2625d2f6961d1a8dd3958eac51a5

Changed in keystone:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in keystone:
milestone: none → havana-3
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in keystone:
milestone: havana-3 → 2013.2
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.