diff options
| author | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2013-07-26 15:16:13 +0000 |
|---|---|---|
| committer | Johannes Erdfelt <johannes.erdfelt@rackspace.com> | 2013-07-26 20:20:25 +0000 |
| commit | df3f2bafbe76d78d017d40e7dc08909fee7dbe34 (patch) | |
| tree | 839406bbf4f76adb436ff04162b459a6b916273b /openstack | |
| parent | d4d81262ff74ff54e51db4065192fd9a0119ec34 (diff) | |
| download | oslo-df3f2bafbe76d78d017d40e7dc08909fee7dbe34.tar.gz oslo-df3f2bafbe76d78d017d40e7dc08909fee7dbe34.tar.xz oslo-df3f2bafbe76d78d017d40e7dc08909fee7dbe34.zip | |
BaseException.message is deprecated since Python 2.6
PEP 352 deprecated the message attribute of the BaseException class.
Using the message attribute will result in warnings like this:
DeprecationWarning: BaseException.message has been deprecated as of Python 2.6
Using unicode(exc) is the suggested replacement.
Change-Id: Ibf3c56e4baa6ad83e2b95a948787e9d02cf074d4
Diffstat (limited to 'openstack')
| -rw-r--r-- | openstack/common/db/sqlalchemy/session.py | 10 | ||||
| -rw-r--r-- | openstack/common/excutils.py | 7 | ||||
| -rw-r--r-- | openstack/common/timeutils.py | 4 |
3 files changed, 16 insertions, 5 deletions
diff --git a/openstack/common/db/sqlalchemy/session.py b/openstack/common/db/sqlalchemy/session.py index 59bcb90..e83009c 100644 --- a/openstack/common/db/sqlalchemy/session.py +++ b/openstack/common/db/sqlalchemy/session.py @@ -478,6 +478,11 @@ def _raise_if_duplicate_entry_error(integrity_error, engine_name): if engine_name not in ["mysql", "sqlite", "postgresql"]: return + # FIXME(johannes): The usage of the .message attribute has been + # deprecated since Python 2.6. However, the exceptions raised by + # SQLAlchemy can differ when using unicode() and accessing .message. + # An audit across all three supported engines will be necessary to + # ensure there are no regressions. m = _DUP_KEY_RE_DB[engine_name].match(integrity_error.message) if not m: return @@ -510,6 +515,11 @@ def _raise_if_deadlock_error(operational_error, engine_name): re = _DEADLOCK_RE_DB.get(engine_name) if re is None: return + # FIXME(johannes): The usage of the .message attribute has been + # deprecated since Python 2.6. However, the exceptions raised by + # SQLAlchemy can differ when using unicode() and accessing .message. + # An audit across all three supported engines will be necessary to + # ensure there are no regressions. m = re.match(operational_error.message) if not m: return diff --git a/openstack/common/excutils.py b/openstack/common/excutils.py index abe6f87..664b2e4 100644 --- a/openstack/common/excutils.py +++ b/openstack/common/excutils.py @@ -77,7 +77,8 @@ def forever_retry_uncaught_exceptions(infunc): try: return infunc(*args, **kwargs) except Exception as exc: - if exc.message == last_exc_message: + this_exc_message = unicode(exc) + if this_exc_message == last_exc_message: exc_count += 1 else: exc_count = 1 @@ -85,12 +86,12 @@ def forever_retry_uncaught_exceptions(infunc): # the exception message changes cur_time = int(time.time()) if (cur_time - last_log_time > 60 or - exc.message != last_exc_message): + this_exc_message != last_exc_message): logging.exception( _('Unexpected exception occurred %d time(s)... ' 'retrying.') % exc_count) last_log_time = cur_time - last_exc_message = exc.message + last_exc_message = this_exc_message exc_count = 0 # This should be a very rare event. In case it isn't, do # a sleep. diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py index bd60489..aa9f708 100644 --- a/openstack/common/timeutils.py +++ b/openstack/common/timeutils.py @@ -49,9 +49,9 @@ def parse_isotime(timestr): try: return iso8601.parse_date(timestr) except iso8601.ParseError as e: - raise ValueError(e.message) + raise ValueError(unicode(e)) except TypeError as e: - raise ValueError(e.message) + raise ValueError(unicode(e)) def strtime(at=None, fmt=PERFECT_TIME_FORMAT): |
