summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Podoliaka <rpodolyaka@mirantis.com>2016-02-08 11:51:27 +0200
committerRoman Podoliaka <rpodolyaka@mirantis.com>2016-02-08 16:01:22 +0200
commit029f0966b2fbd8a66d0561d4927ef47b5f67ac3f (patch)
treec3593cd7b03f750c34db5aa5bb8bceba767c6afe
parent5f9936119619117dbec457cab1245a0c4838946d (diff)
downloadoslo-db-029f0966b2fbd8a66d0561d4927ef47b5f67ac3f.tar.gz
exceptions: provide .message attribute for Py3K compatibility4.4.0
In two recent commits we fixed the way .message class attribute was used by passing it as an argument to __init__() of the base Exception class instead. Unfortunately, this currently breaks Heat unit tests on Py3K as exception instances no longer provide .message attribute there. Re-introduce .message properties only for exception classes that used to have them to ensure the new oslo.db release do not change the interface of exceptions. Closes-Bug: #1542961 Change-Id: I5cae408555956d77e6cbb4e5e513c1c6c375d29d
-rw-r--r--oslo_db/exception.py15
-rw-r--r--oslo_db/tests/sqlalchemy/test_utils.py6
2 files changed, 21 insertions, 0 deletions
diff --git a/oslo_db/exception.py b/oslo_db/exception.py
index 715bbc1..c5e0fa9 100644
--- a/oslo_db/exception.py
+++ b/oslo_db/exception.py
@@ -43,6 +43,7 @@ with `try/except` statement. This is required for consistent handling of
database errors.
"""
+import debtcollector.removals
import six
from oslo_db._i18n import _
@@ -147,6 +148,13 @@ class DBInvalidUnicodeParameter(Exception):
without encoding directive.
"""
+ @debtcollector.removals.removed_property
+ def message(self):
+ # NOTE(rpodolyaka): provided for compatibility with python 3k, where
+ # exceptions do not have .message attribute, while we used to have one
+ # in this particular exception class. See LP #1542961 for details.
+ return str(self)
+
def __init__(self):
super(DBInvalidUnicodeParameter, self).__init__(
_("Invalid Parameter: Encoding directive wasn't provided."))
@@ -184,6 +192,13 @@ class DBDataError(DBError):
class InvalidSortKey(Exception):
"""A sort key destined for database query usage is invalid."""
+ @debtcollector.removals.removed_property
+ def message(self):
+ # NOTE(rpodolyaka): provided for compatibility with python 3k, where
+ # exceptions do not have .message attribute, while we used to have one
+ # in this particular exception class. See LP #1542961 for details.
+ return str(self)
+
def __init__(self, key=None):
super(InvalidSortKey, self).__init__(
_("Sort key supplied is invalid: %s") % key)
diff --git a/oslo_db/tests/sqlalchemy/test_utils.py b/oslo_db/tests/sqlalchemy/test_utils.py
index 405619f..a3e7e1a 100644
--- a/oslo_db/tests/sqlalchemy/test_utils.py
+++ b/oslo_db/tests/sqlalchemy/test_utils.py
@@ -153,11 +153,17 @@ class TestPaginateQuery(test_base.BaseTestCase):
str(exception.InvalidSortKey()))
self.assertEqual("Sort key supplied is invalid: lol",
str(exception.InvalidSortKey("lol")))
+ self.assertEqual("Sort key supplied is invalid: lol",
+ exception.InvalidSortKey("lol").message)
def test_invalid_unicode_paramater_str(self):
self.assertEqual(
"Invalid Parameter: Encoding directive wasn't provided.",
str(exception.DBInvalidUnicodeParameter()))
+ self.assertEqual(
+ "Invalid Parameter: Encoding directive wasn't provided.",
+ exception.DBInvalidUnicodeParameter().message
+ )
def test_paginate_query_attribute_error(self):
sqlalchemy.asc(self.model.user_id).AndReturn('asc')