using deprecated message attribute of the Exception class

Bug #1648584 reported by Jin Li
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Gluon
Fix Released
Undecided
Jin Li

Bug Description

The message attribute of the Exception class has been deprecated after the python 2.7 : https://www.python.org/dev/peps/pep-0352/. Calling Exception.message will cause python 3.4 to fail.

Below is an example in the gluon/particleGenerator/cli.py module, the do_post function fails a uni test case which triggers it to call the e.message.

The do_post function:
def do_post(url, values):
    resp = post(url, json=values)
    if resp.status_code != 200 and resp.status_code != 201:
        raise exc.GluonClientException('Bad return status %d'
                                       % resp.status_code,
                                       status_code=resp.status_code)
    try:
        rv = json.loads(resp.content)
    except Exception as e:
        raise exc.MalformedResponseBody(reason="JSON unreadable: %s on %s"
                                               % (e.message, resp.content))
    return rv

uni test case:
    @mock.patch.object(cli, "post")
    def test_do_post_badRspBody(self, mock_post):
        rsp = mock.Mock()
        rsp.status_code = 200
        rsp.content = "response in wrong json format"
        mock_post.return_value = rsp
        jsonValue = {"foo": "bar"}
        self.assertRaises(exc.MalformedResponseBody,
                          cli.do_post,
                          'www.gluonURL.net',
                          jsonValue)

Python34 test result with error:
2016-12-03 02:12:33.808892 | ======================================================================
2016-12-03 02:12:33.808914 | FAIL: gluon.tests.particleGenerator.test_cli.CliTestCase.test_do_post_badRspBody
2016-12-03 02:12:33.808923 | tags: worker-7
2016-12-03 02:12:33.808944 | ----------------------------------------------------------------------
2016-12-03 02:12:33.808957 | Empty attachments:
2016-12-03 02:12:33.808965 | stderr
2016-12-03 02:12:33.808973 | stdout
2016-12-03 02:12:33.808978 |
2016-12-03 02:12:33.808991 | Traceback (most recent call last):
2016-12-03 02:12:33.809019 | File "/home/jenkins/workspace/gate-gluon-python34/gluon/particleGenerator/cli.py", line 116, in do_post
2016-12-03 02:12:33.809032 | rv = json.loads(resp.content)
2016-12-03 02:12:33.809052 | File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
2016-12-03 02:12:33.809065 | return _default_decoder.decode(s)
2016-12-03 02:12:33.809096 | File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
2016-12-03 02:12:33.809115 | obj, end = self.raw_decode(s, idx=_w(s, 0).end())
2016-12-03 02:12:33.809135 | File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
2016-12-03 02:12:33.809156 | raise ValueError(errmsg("Expecting value", s, err.value)) from None
2016-12-03 02:12:33.809173 | ValueError: Expecting value: line 1 column 1 (char 0)
2016-12-03 02:12:33.809179 |
2016-12-03 02:12:33.809199 | During handling of the above exception, another exception occurred:
2016-12-03 02:12:33.809205 |
2016-12-03 02:12:33.809217 | Traceback (most recent call last):
2016-12-03 02:12:33.809250 | File "/home/jenkins/workspace/gate-gluon-python34/.tox/py34/lib/python3.4/site-packages/mock/mock.py", line 1305, in patched
2016-12-03 02:12:33.809264 | return func(*args, **keywargs)
2016-12-03 02:12:33.809298 | File "/home/jenkins/workspace/gate-gluon-python34/gluon/tests/particleGenerator/test_cli.py", line 204, in test_do_post_badRspBody
2016-12-03 02:12:33.809307 | jsonValue)
2016-12-03 02:12:33.809342 | File "/home/jenkins/workspace/gate-gluon-python34/.tox/py34/lib/python3.4/site-packages/testtools/testcase.py", line 485, in assertRaises
2016-12-03 02:12:33.809357 | self.assertThat(our_callable, matcher)
2016-12-03 02:12:33.809392 | File "/home/jenkins/workspace/gate-gluon-python34/.tox/py34/lib/python3.4/site-packages/testtools/testcase.py", line 496, in assertThat
2016-12-03 02:12:33.809413 | mismatch_error = self._matchHelper(matchee, matcher, message, verbose)
2016-12-03 02:12:33.809449 | File "/home/jenkins/workspace/gate-gluon-python34/.tox/py34/lib/python3.4/site-packages/testtools/testcase.py", line 547, in _matchHelper
2016-12-03 02:12:33.809463 | mismatch = matcher.match(matchee)
2016-12-03 02:12:33.809499 | File "/home/jenkins/workspace/gate-gluon-python34/.tox/py34/lib/python3.4/site-packages/testtools/matchers/_exception.py", line 108, in match
2016-12-03 02:12:33.809516 | mismatch = self.exception_matcher.match(exc_info)
2016-12-03 02:12:33.809553 | File "/home/jenkins/workspace/gate-gluon-python34/.tox/py34/lib/python3.4/site-packages/testtools/matchers/_higherorder.py", line 62, in match
2016-12-03 02:12:33.809567 | mismatch = matcher.match(matchee)
2016-12-03 02:12:33.809601 | File "/home/jenkins/workspace/gate-gluon-python34/.tox/py34/lib/python3.4/site-packages/testtools/testcase.py", line 475, in match
2016-12-03 02:12:33.809611 | reraise(*matchee)
2016-12-03 02:12:33.809646 | File "/home/jenkins/workspace/gate-gluon-python34/.tox/py34/lib/python3.4/site-packages/testtools/_compat3x.py", line 16, in reraise
2016-12-03 02:12:33.809660 | raise exc_obj.with_traceback(exc_tb)
2016-12-03 02:12:33.809696 | File "/home/jenkins/workspace/gate-gluon-python34/.tox/py34/lib/python3.4/site-packages/testtools/matchers/_exception.py", line 101, in match
2016-12-03 02:12:33.809706 | result = matchee()
2016-12-03 02:12:33.809741 | File "/home/jenkins/workspace/gate-gluon-python34/.tox/py34/lib/python3.4/site-packages/testtools/testcase.py", line 1049, in __call__
2016-12-03 02:12:33.809760 | return self._callable_object(*self._args, **self._kwargs)
2016-12-03 02:12:33.809790 | File "/home/jenkins/workspace/gate-gluon-python34/gluon/particleGenerator/cli.py", line 119, in do_post
2016-12-03 02:12:33.809803 | % (e.message, resp.content))
2016-12-03 02:12:33.809829 | AttributeError: 'ValueError' object has no attribute 'message'

Jin Li (jl7351)
Changed in python-gluon:
assignee: nobody → Jin Li (jl7351)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to gluon (master)

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

Changed in python-gluon:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to gluon (master)

Reviewed: https://review.openstack.org/411003
Committed: https://git.openstack.org/cgit/openstack/gluon/commit/?id=8c21b6a2e98315f22ffdbae511399ff441e4d131
Submitter: Jenkins
Branch: master

commit 8c21b6a2e98315f22ffdbae511399ff441e4d131
Author: JinLi <email address hidden>
Date: Wed Dec 14 15:42:33 2016 -0800

    Fix Exception.message deprecated error

    some places in our code still use Exception.message which has been
    deprecated after python2.6. and cause test cases to fail.
    Change it to Excepton.args[0] to fix this issue. Test cases for this
    change is in this patch: https://review.openstack.org/#/c/405689/

    Change-Id: I7ca0549847fa7f165a9c3bf1e2659c0572a13b6c
    Closes-Bug: #1648584

Changed in python-gluon:
status: In Progress → Fix Released
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.