Skip to content

Commit

Permalink
DB try/catch bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio Massacci committed Apr 4, 2024
1 parent d6cfc50 commit 7cc3630
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions terra-update-batch/modules/cosmoUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def copyFileToDb(table_mapping, db_settings, db_schemas, db_column_type, logger)
def receive_before_cursor_execute(conn, cursor, statement, params, context, executemany):
if executemany:
cursor.fast_executemany = True

try:
with engine.connect() as con:
with engine.connect() as con:
try:
# TRUNCATE STAGING TABLE
for file, table in table_mapping.items():
logger.info(f'Truncating staging table {table}')
Expand Down Expand Up @@ -166,12 +166,12 @@ def receive_before_cursor_execute(conn, cursor, statement, params, context, exec

logger.info("copyFileToDb END")

except BaseException as e:
logger.info(f'Error during copy file to DB: {e}')
finally:
engine.dispose()
con.close()
return
except BaseException as e:
logger.info(f'Error during copy file to DB: {e}')
finally:
engine.dispose()
con.close()
return

def exportOutputs(logger):
logger.info("exportOutputs START")
Expand Down

0 comments on commit 7cc3630

Please sign in to comment.