diff --git a/terra-update-batch/modules/cosmoUtility.py b/terra-update-batch/modules/cosmoUtility.py index aede655..f9bd8f0 100644 --- a/terra-update-batch/modules/cosmoUtility.py +++ b/terra-update-batch/modules/cosmoUtility.py @@ -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}') @@ -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")