Commit 0d36de7b authored by Julien Muchembled's avatar Julien Muchembled

Fix 2 'except' statements that will bug when moving to Python 3

Previous code relied on the fact that the exception target is kept past
the end of the except clause. 2to3 is not smart enough to detect that.

Without this change, a different OperationalError exception would be
ignored because there's already a local variable of the same name.
parent b0023b43
...@@ -124,18 +124,19 @@ class NEOLogger(Logger): ...@@ -124,18 +124,19 @@ class NEOLogger(Logger):
def commit(self): def commit(self):
try: try:
self._db.commit() self._db.commit()
except sqlite3.OperationalError, e: except sqlite3.OperationalError as e:
x = e.args[0] x = e.args[0]
if x == 'database is locked': if x != 'database is locked':
sys.stderr.write('%s: retrying to emit log...' % x) raise
while e.args[0] == x: sys.stderr.write('%s: retrying to emit log...' % x)
try: while 1:
self._db.commit() try:
except sqlite3.OperationalError, e: self._db.commit()
continue break
sys.stderr.write(' ok\n') except sqlite3.OperationalError as e:
return if e.args[0] != x:
raise raise
sys.stderr.write(' ok\n')
def backlog(self, max_size=1<<24, max_packet=None): def backlog(self, max_size=1<<24, max_packet=None):
with self: with self:
......
...@@ -42,18 +42,19 @@ def unique_constraint_message(table, *columns): ...@@ -42,18 +42,19 @@ def unique_constraint_message(table, *columns):
def retry_if_locked(f, *args): def retry_if_locked(f, *args):
try: try:
return f(*args) return f(*args)
except sqlite3.OperationalError, e: except sqlite3.OperationalError as e:
x = e.args[0] x = e.args[0]
if x == 'database is locked': if x != 'database is locked':
msg = traceback.format_exception_only(type(e), e) raise
msg += traceback.format_stack() msg = traceback.format_exception_only(type(e), e)
logging.warning(''.join(msg)) msg += traceback.format_stack()
while e.args[0] == x: logging.warning(''.join(msg))
try: while 1:
return f(*args) try:
except sqlite3.OperationalError, e: return f(*args)
pass except sqlite3.OperationalError as e:
raise if e.args[0] != x:
raise
class SQLiteDatabaseManager(DatabaseManager): class SQLiteDatabaseManager(DatabaseManager):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment