Fix transaction error in unit test

In galaxy, HistoryAudit.prune() executes in the context of a separate thread, where it
starts and commits a new transaction, closing a scoped session on exit. Thus, here we
should end the current transaction (via rollback) and add the History objects to a new
session, as the previous one will be closed.
This commit is contained in:
John Davis
2023-06-09 13:05:26 -04:00
parent 889eabcc32
commit 70285d0ee0
+7 -1
View File
@@ -661,7 +661,7 @@ class TestMappings(BaseModelTestCase):
self.new_hda(h1, name="1")
self.new_hda(h2, name="2")
self.session().flush()
self.session().commit()
# _next_hid modifies history, plus trigger on HDA means 2 additional audit rows per history
h1_audits = get_audit_table_entries(h1)
@@ -672,7 +672,13 @@ class TestMappings(BaseModelTestCase):
h1_latest = get_latest_entry(h1_audits)
h2_latest = get_latest_entry(h2_audits)
# In galaxy, HistoryAudit.prune() executes in the context of a separate thread, where it
# starts and commits a new transaction, closing a scoped session on exit. Thus, here we
# should end the current transaction (via rollback) and add the History objects to a new
# session, as the previous one will be closed.
self.session().rollback()
model.HistoryAudit.prune(self.session())
self.session().add_all([h1, h2])
h1_audits = get_audit_table_entries(h1)
h2_audits = get_audit_table_entries(h2)