diff --git a/lib/open_project/reporting/patches/custom_fields_controller_patch.rb b/lib/open_project/reporting/patches/custom_fields_controller_patch.rb index d595737902..46df37498f 100644 --- a/lib/open_project/reporting/patches/custom_fields_controller_patch.rb +++ b/lib/open_project/reporting/patches/custom_fields_controller_patch.rb @@ -34,13 +34,17 @@ module OpenProject::Reporting::Patches def destroy_with_custom_fields id = @custom_field.id - - reports = CostQuery.where("serialized LIKE '%CustomField#{id}%'") - - remove_custom_field_from_cost_report(reports, id) - remove_custom_field_from_session(id) - - destroy_without_custom_fields + begin + reports = CostQuery.where("serialized LIKE '%CustomField#{id}%'") + + remove_custom_field_from_cost_report(reports, id) + remove_custom_field_from_session(id) + rescue => e + Rails.logger.error "Failed to remove custom_field #{id} from custom queries. " \ + "#{e.class}: #{e.message}" + ensure + destroy_without_custom_fields + end end private