OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#57612] Work package Report export fails if work package has unavailable attachments
as-opc1b61fc67b70
diff --git a/app/models/work_package/pdf_export/markdown.rb b/app/models/work_package/pdf_export/markdown.rbindex bfcf94e0401..b03e89cd38d 100644--- a/app/models/work_package/pdf_export/markdown.rb+++ b/app/models/work_package/pdf_export/markdown.rb@@ -105,12 +105,24 @@ module WorkPackage::PDFExport::Markdownprivate+ def attachment_image_local_file(attachment)+ return nil if attachment.nil?++ attachment.file.local_file+ rescue StandardError => e+ Rails.logger.error "Failed to access attachment #{attachment.id} file: #{e}"+ nil # return nil as if the id was wrong and the attachment obj has not been found+ end+def attachment_image_filepath(work_package, src)# images are embedded into markup with the api-path as img.srcattachment = attachment_by_api_content_src(work_package, src)- return nil if attachment.nil? || attachment.file.local_file.nil? || !pdf_embeddable?(attachment.content_type)+ return nil if attachment.nil? || !pdf_embeddable?(attachment.content_type)++ local_file = attachment_image_local_file(attachment)+ return nil if local_file.nil?- resize_image(attachment.file.local_file.path)+ resize_image(local_file.path)enddef attachment_by_api_content_src(work_package, src)diff --git a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rbindex d73b936f128..f898900a00e 100644--- a/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb+++ b/spec/models/work_packages/pdf_export/work_package_to_pdf_spec.rb@@ -244,6 +244,20 @@ RSpec.describe WorkPackage::PDFExport::WorkPackageToPdf doendend+ describe "with a faulty image" do+ before do+ # simulate a null pointer exception+ # https://appsignal.com/openproject-gmbh/sites/62a6d833d2a5e482c1ef825d/exceptions/incidents/2326/samples/62a6d833d2a5e482c1ef825d-848752493603098719217252846401+ # where attachment data is in the database but the file is missing, corrupted or not accessible+ allow(image_attachment).to receive(:file)+ .and_return(nil)+ end++ it "still finishes the export" do+ expect(pdf[:images].length).to eq(0)+ end+ end+describe "with embedded work package attributes" dolet(:supported_work_package_embeds) do[