Skip to content

Commit 1059efd

Browse files
committed
add transactions to SQLTempTableDumper
1 parent 60f493a commit 1059efd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

datapackage_pipelines_knesset/processors/dump_to_sql.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,18 @@ def handle_resource(self, resource, spec, parameters, datapackage):
165165
def finalize(self):
166166
if os.environ.get('DUMP_TO_SQL'):
167167
connection = self.engine.connect()
168+
transaction = connection.begin()
168169
try:
169170
for temp_table_name, table_name in self.rename_table_names.items():
170171
logging.info('renaming sql table {} --> {}'.format(temp_table_name, table_name))
171172
connection.execute(dedent('''
172173
drop table if exists "{table_name}";
173174
alter table "{temp_table_name}" rename to "{table_name}";
174175
''').format(table_name=table_name, temp_table_name=temp_table_name))
176+
transaction.commit()
177+
except:
178+
transaction.rollback()
179+
raise
175180
finally:
176181
connection.close()
177182
super(SQLTempTableDumper, self).finalize()

0 commit comments

Comments
 (0)