URL: https://github.com/freeipa/freeipa/pull/1134
Author: stlaz
 Title: #1134: [Backport][ipa-4-6] Remove the `message` attribute from 
exceptions
Action: opened

PR body:
"""
This PR was opened automatically because PR #1121 was pushed to master and 
backport to ipa-4-6 is required.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1134/head:pr1134
git checkout pr1134
From ec7a618f914b0df60eecf947d5d523846e0f8eca Mon Sep 17 00:00:00 2001
From: Stanislav Laznicka <slazn...@redhat.com>
Date: Tue, 3 Oct 2017 12:36:21 +0200
Subject: [PATCH] Remove the `message` attribute from exceptions

This is causing python2 tests print ugly warnings about the
deprecation of the `message` attribute in python2.6.

https://pagure.io/freeipa/issue/7131
---
 ipalib/errors.py                        |  2 +-
 ipalib/messages.py                      |  5 -----
 ipaserver/install/installutils.py       |  2 +-
 ipaserver/plugins/group.py              |  2 +-
 ipatests/test_ipalib/test_errors.py     | 19 ++++++-------------
 ipatests/test_webui/test_user.py        |  3 ++-
 ipatests/test_xmlrpc/test_dns_plugin.py |  4 ++--
 7 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/ipalib/errors.py b/ipalib/errors.py
index 6aaca708a0..fb7fb4e2a9 100644
--- a/ipalib/errors.py
+++ b/ipalib/errors.py
@@ -369,7 +369,7 @@ class ServerCommandError(PublicError):
     For example:
 
     >>> e = CommandError(name='foobar')
-    >>> raise ServerCommandError(error=e.message, server='https://localhost')
+    >>> raise ServerCommandError(error=str(e), server='https://localhost')
     Traceback (most recent call last):
       ...
     ServerCommandError: error on server 'https://localhost': unknown command 'foobar'
diff --git a/ipalib/messages.py b/ipalib/messages.py
index 02b0a0e102..fd458a1757 100644
--- a/ipalib/messages.py
+++ b/ipalib/messages.py
@@ -129,11 +129,6 @@ def to_dict(self):
             data=self.kw,
         )
 
-    if six.PY3:
-        @property
-        def message(self):
-            return str(self)
-
 
 class VersionMissing(PublicMessage):
     """
diff --git a/ipaserver/install/installutils.py b/ipaserver/install/installutils.py
index 8983718950..c525f945a3 100644
--- a/ipaserver/install/installutils.py
+++ b/ipaserver/install/installutils.py
@@ -969,7 +969,7 @@ def handle_error(error, log_file_name=None):
         return error, 1
 
     if isinstance(error, errors.ACIError):
-        return error.message, 1
+        return str(error), 1
     if isinstance(error, ldap.INVALID_CREDENTIALS):
         return "Invalid password", 1
     if isinstance(error, ldap.INSUFFICIENT_ACCESS):
diff --git a/ipaserver/plugins/group.py b/ipaserver/plugins/group.py
index 1fb092d5f0..5e94272396 100644
--- a/ipaserver/plugins/group.py
+++ b/ipaserver/plugins/group.py
@@ -439,7 +439,7 @@ def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs)
         # using --setattr.
         if call_func.__name__ == 'update_entry':
             if isinstance(exc, errors.ObjectclassViolation):
-                if 'gidNumber' in exc.message and 'posixGroup' in exc.message:
+                if 'gidNumber' in str(exc) and 'posixGroup' in str(exc):
                     raise errors.RequirementError(name='gidnumber')
         raise exc
 
diff --git a/ipatests/test_ipalib/test_errors.py b/ipatests/test_ipalib/test_errors.py
index 893a3e9b92..04b6e57417 100644
--- a/ipatests/test_ipalib/test_errors.py
+++ b/ipatests/test_ipalib/test_errors.py
@@ -65,7 +65,6 @@ def new(self, **kw):
         for (key, value) in kw.items():
             assert getattr(inst, key) is value
         assert str(inst) == self.klass.format % kw
-        assert inst.message == str(inst)
         return inst
 
 
@@ -119,7 +118,6 @@ def test_init(self):
         assert inst.returncode == 1
         assert inst.argv == (bin_false,)
         assert str(inst) == "return code 1 from ('{}',)".format(bin_false)
-        assert inst.message == str(inst)
 
 
 class test_PluginSubclassError(PrivateExceptionTester):
@@ -138,7 +136,6 @@ def test_init(self):
         assert inst.bases == ('base1', 'base2')
         assert str(inst) == \
             "'bad' not subclass of any base in ('base1', 'base2')"
-        assert inst.message == str(inst)
 
 
 class test_PluginDuplicateError(PrivateExceptionTester):
@@ -155,7 +152,6 @@ def test_init(self):
         inst = self.new(plugin='my_plugin')
         assert inst.plugin == 'my_plugin'
         assert str(inst) == "'my_plugin' was already registered"
-        assert inst.message == str(inst)
 
 
 class test_PluginOverrideError(PrivateExceptionTester):
@@ -174,7 +170,6 @@ def test_init(self):
         assert inst.name == 'cmd'
         assert inst.plugin == 'my_cmd'
         assert str(inst) == "unexpected override of Base.cmd with 'my_cmd'"
-        assert inst.message == str(inst)
 
 
 class test_PluginMissingOverrideError(PrivateExceptionTester):
@@ -193,8 +188,6 @@ def test_init(self):
         assert inst.name == 'cmd'
         assert inst.plugin == 'my_cmd'
         assert str(inst) == "Base.cmd not registered, cannot override with 'my_cmd'"
-        assert inst.message == str(inst)
-
 
 
 ##############################################################################
@@ -250,7 +243,7 @@ def test_init(self):
         # Test with format=str, message=None
         inst = self.klass(format, **kw)
         assert inst.format is format
-        assert_equal(inst.message, format % kw)
+        assert_equal(str(inst), format % kw)
         assert inst.forwarded is False
         assert inst.key1 is val1
         assert inst.key2 is val2
@@ -258,7 +251,7 @@ def test_init(self):
         # Test with format=None, message=unicode
         inst = self.klass(message=message, **kw)
         assert inst.format is None
-        assert inst.message is message
+        assert str(inst) == message
         assert inst.strerror is message
         assert inst.forwarded is True
         assert inst.key1 is val1
@@ -281,7 +274,7 @@ def test_init(self):
         inst = self.new(format, **kw)
         assert isinstance(inst, self.klass)
         assert inst.format is format
-        assert_equal(inst.message, format % kw)
+        assert_equal(str(inst), format % kw)
         assert inst.forwarded is False
         assert inst.key1 is val1
         assert inst.key2 is val2
@@ -290,7 +283,7 @@ def test_init(self):
         inst = self.new(message=message, **kw)
         assert isinstance(inst, self.klass)
         assert inst.format is None
-        assert inst.message is message
+        assert str(inst) == message
         assert inst.strerror is message
         assert inst.forwarded is True
         assert inst.key1 is val1
@@ -312,7 +305,7 @@ class subclass(self.klass):
         # Test with format=None, message=None:
         inst = subclass(**kw)
         assert inst.format is subclass.format
-        assert_equal(inst.message, subclass.format % kw)
+        assert_equal(str(inst), subclass.format % kw)
         assert inst.forwarded is False
         assert inst.true is True
         assert inst.text is kw['text']
@@ -321,7 +314,7 @@ class subclass(self.klass):
         # Test with format=None, message=unicode:
         inst = subclass(message=message, **kw)
         assert inst.format is subclass.format
-        assert inst.message is message
+        assert str(inst) == message
         assert inst.strerror is message
         assert inst.forwarded is True
         assert inst.true is True
diff --git a/ipatests/test_webui/test_user.py b/ipatests/test_webui/test_user.py
index c58e0eda1e..bf3d359408 100644
--- a/ipatests/test_webui/test_user.py
+++ b/ipatests/test_webui/test_user.py
@@ -383,7 +383,8 @@ def test_noprivate_nonposix(self):
 
         with pytest.raises(AssertionError) as e:
             self.add_record(user.ENTITY, user.DATA3)
-        assert e.value.message == u'Unexpected error: Default group for new users is not POSIX'
+        assert (str(e.value) == 'Unexpected error: Default group for new '
+                'users is not POSIX')
 
     @screenshot
     def test_noprivate_posix(self):
diff --git a/ipatests/test_xmlrpc/test_dns_plugin.py b/ipatests/test_xmlrpc/test_dns_plugin.py
index 487e7920d3..68d7c4ae29 100644
--- a/ipatests/test_xmlrpc/test_dns_plugin.py
+++ b/ipatests/test_xmlrpc/test_dns_plugin.py
@@ -1156,8 +1156,8 @@ def setup_class(cls):
                                                                      % zone1_ns]}),
             expected=lambda x, output: (
                 type(x) == errors.ValidationError and
-                x.message.endswith(u'Raw value of a DNS record was already '
-                                   u'set by "srv_rec" option'),
+                str(x).endswith('Raw value of a DNS record was already '
+                                'set by "srv_rec" option'),
             ),
         ),
 
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to