Close session after execute. (#2677)

This commit is contained in:
Johann Kellerman 2016-07-31 19:10:30 +02:00 committed by Paulus Schoutsen
parent a81a8c2bdf
commit 74f284d2d7

View File

@ -58,14 +58,17 @@ def execute(q):
This method also retries a few times in the case of stale connections.
"""
import sqlalchemy.exc
for _ in range(0, RETRIES):
try:
return [
row for row in
(row.to_native() for row in q)
if row is not None]
except sqlalchemy.exc.SQLAlchemyError as e:
log_error(e, retry_wait=QUERY_RETRY_WAIT, rollback=True)
try:
for _ in range(0, RETRIES):
try:
return [
row for row in
(row.to_native() for row in q)
if row is not None]
except sqlalchemy.exc.SQLAlchemyError as e:
log_error(e, retry_wait=QUERY_RETRY_WAIT, rollback=True)
finally:
Session().close()
return []