summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2014-10-27 21:18:07 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2014-10-27 21:21:10 -0700
commit135701b202e97abce065203a68e45a89b0a3bd3b (patch)
tree7e8dc4783a8fad5a9da09a28fa18ef76546778b5
parent490f6442be3fb6d94f44f4ac2898a2a71ba5e6d1 (diff)
downloadoslo-db-135701b202e97abce065203a68e45a89b0a3bd3b.tar.gz
Fix python3.x scoping issues with removed 'de' variable
In python3.x the 'de' variable will be removed from the scope after the except block exits (if it ever is entered) so we need to use a different variable name to ensure that it will not be deleted so we can use it later. This avoids errors of the format: UnboundLocalError: local variable 'de' referenced before assignment Change-Id: I9ea2bd6b3a8c392f8d27b0130dd6b7683fc44e7c
-rw-r--r--oslo/db/sqlalchemy/session.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/oslo/db/sqlalchemy/session.py b/oslo/db/sqlalchemy/session.py
index b24e06b..04644b5 100644
--- a/oslo/db/sqlalchemy/session.py
+++ b/oslo/db/sqlalchemy/session.py
@@ -569,7 +569,10 @@ def _test_connection(engine, max_retries, retry_interval):
attempts = itertools.count()
else:
attempts = six.moves.range(max_retries)
- de = None
+ # See: http://legacy.python.org/dev/peps/pep-3110/#semantic-changes for
+ # why we are not using 'de' directly (it can be removed from the local
+ # scope).
+ de_ref = None
for attempt in attempts:
try:
return exc_filters.handle_connect_error(engine)
@@ -577,9 +580,10 @@ def _test_connection(engine, max_retries, retry_interval):
msg = _LW('SQL connection failed. %s attempts left.')
LOG.warning(msg, max_retries - attempt)
time.sleep(retry_interval)
+ de_ref = de
else:
- if de is not None:
- six.reraise(type(de), de)
+ if de_ref is not None:
+ six.reraise(type(de_ref), de_ref)
class Query(sqlalchemy.orm.query.Query):