message doesn't set properly on ClientException

Bug #1534363 reported by Everett Toews
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
keystoneauth
Fix Released
Medium
David Stanek

Bug Description

To reproduce

    >>> from keystoneauth1 import exceptions
    >>> e = exceptions.ClientException(message="test")
    >>> print(e.message)
    None

Also, it seems that if you want to follow the proper idiom for calling a super class init method then this line [1] should be

    super(ClientException, self).__init__(message)

[1] http://git.openstack.org/cgit/openstack/keystoneauth/tree/keystoneauth1/exceptions/base.py#n27

Revision history for this message
Morgan Fainberg (mdrnstm) wrote :

Yep, looks like the issue is the superclass .__init__ call.

Changed in keystoneauth:
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to keystoneauth (master)

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

Changed in keystoneauth:
assignee: nobody → Tin Lam (tl3438)
status: Confirmed → In Progress
Revision history for this message
Dolph Mathews (dolph) wrote :

What's wrong with this?

  >>> from keystoneauth1 import exceptions
  >>> e = exceptions.ClientException(message="test")
  >>> print(e)
  test

Revision history for this message
Everett Toews (everett-toews) wrote :

At the very least it violates the principle of least surprise.

If I do

    e = exceptions.ClientException(message="test")

I fully expect that

    e.message

will have the message that was set.

Also the repr can and should be able to change. Clients should never depend on the output of repr.

e.message provides some structure that clients can depend on.

Revision history for this message
Tin Lam (lamt) wrote :

Per Brant Knudson's comment, we can rename the message field to _message to allow for this in Python 2.x. However the message attribute was removed in Python 3.x - I presume the code should mirror that behavior instead of reintroducing that attribute for Python 3.x.

Revision history for this message
David Stanek (dstanek) wrote :

The new version of the code adds the attribute back for Python 3. After thinking about this a bit I'd rather see either:

1. Rename 'message' to something else like 'default' (since that's what it is anyway). This means that in Python 2 the `e.message` will be what gets computed and passed into the parent's __init__ and in Python 3 there will be no `e.message`. The lack of a `message` attribute in Python 3 isn't a problem for me since it's a well known, well documented compatibility issue.

2. Do something cooler, which I suspect rules it out, but we could pull the message from the `__doc__` and define exceptions like:

    class E(ClientException):
        """An error while doing something"""

Revision history for this message
Lance Bragstad (lbragstad) wrote :

Automatically unassigning due to inactivity.

Changed in keystoneauth:
assignee: Tin Lam (tl3438) → nobody
Changed in keystoneauth:
assignee: nobody → Gage Hugo (gagehugo)
Changed in keystoneauth:
assignee: Gage Hugo (gagehugo) → Tin Lam (tl3438)
Changed in keystoneauth:
assignee: Tin Lam (tl3438) → David Stanek (dstanek)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to keystoneauth (master)

Reviewed: https://review.openstack.org/285757
Committed: https://git.openstack.org/cgit/openstack/keystoneauth/commit/?id=062dcc9cb29556b82ca7182458fac3038dd64c62
Submitter: Jenkins
Branch: master

commit 062dcc9cb29556b82ca7182458fac3038dd64c62
Author: Tin Lam <email address hidden>
Date: Sat Feb 27 21:36:00 2016 -0600

    Fix ClientException message property not set properly

    To reproduce:

        >>> from keystoneauth1 import exceptions
        >>> e = exceptions.ClientException(message="test")
        >>> print(e.message)
        None

    Change-Id: If73df85768866fb93d90ff95479f29f64aabe73f
    Co-Authored-By: Gage Hugo <email address hidden>
    Closes-Bug: #1534363

Changed in keystoneauth:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/keystoneauth 2.19.0

This issue was fixed in the openstack/keystoneauth 2.19.0 release.

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.