From 8bf9e2425bc34d5748d931171196eb66efc3b697 Mon Sep 17 00:00:00 2001 From: Andrej Date: Mon, 20 Mar 2023 14:12:44 +0100 Subject: [PATCH] Fix docx table generator if metadata are nil [SCI-8165] --- app/services/reports/docx/draw_result_table.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/services/reports/docx/draw_result_table.rb b/app/services/reports/docx/draw_result_table.rb index b61445540..fabff641f 100644 --- a/app/services/reports/docx/draw_result_table.rb +++ b/app/services/reports/docx/draw_result_table.rb @@ -8,10 +8,12 @@ module Reports::Docx::DrawResultTable obj = self @docx.p @docx.table JSON.parse(table.contents_utf_8)['data'], border_size: Constants::REPORT_DOCX_TABLE_BORDER_SIZE do - JSON.parse(table.metadata)['cells'].each do |cell| - next unless cell.present? && cell['row'].present? && cell['col'].present? && cell['className'].present? + if table.metadata.present? + JSON.parse(table.metadata)['cells']&.each do |cell| + next unless cell.present? && cell['row'].present? && cell['col'].present? && cell['className'].present? - cell_style rows.dig(cell['row'].to_i, cell['col'].to_i), align: obj.table_cell_alignment(cell['className']) + cell_style rows.dig(cell['row'].to_i, cell['col'].to_i), align: obj.table_cell_alignment(cell['className']) + end end end @docx.p do