From c17192730e032d448989452d41149a453ff34e7d Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Wed, 9 Jun 2021 15:44:38 +0200 Subject: [PATCH] Lock repository_row before inserting RepositoryCell in SavePdfToInventoryItem [SCI-5794] --- app/services/report_actions/save_pdf_to_inventory_item.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/services/report_actions/save_pdf_to_inventory_item.rb b/app/services/report_actions/save_pdf_to_inventory_item.rb index 2371d4966..daa419867 100644 --- a/app/services/report_actions/save_pdf_to_inventory_item.rb +++ b/app/services/report_actions/save_pdf_to_inventory_item.rb @@ -11,7 +11,10 @@ module ReportActions end def save - ActiveRecord::Base.transaction do + # we lock the row, to prevent two repository cells being created at the same location + # as the RepositoryCell validation would pass in both concurrent transactions + + @repository_row.with_lock do asset = create_new_asset delete_old_repository_cell @new_cell_value = create_new_cell_value(asset)