summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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')