Commit 31a3cff7 authored by Stan Hu's avatar Stan Hu

Fix issue CSV export failing for some projects

Some imported projects have NULL values for `label_links.label_id` for
some reason. This caused the issue export CSV to fail because the
exporter attempted to sort an array containing string values and `nil`
values.

We should clean up the database entries
(https://gitlab.com/gitlab-org/gitlab/issues/197307) for this with a NOT
NULL constraint, but this may require some careful consideration. For
now, to make exports work again, we just reject any invalid label links.

Closes https://gitlab.com/gitlab-org/gitlab/issues/197300
parent 2ab56602
---
title: Fix issue CSV export failing for some projects
merge_request: 23223
author:
type: fixed
......@@ -11,7 +11,7 @@ module EE
relation = unscoped.where(id: self.select(:id)).eager_load(:labels)
relation.pluck(:id, 'labels.title').each do |issue_id, label|
issue_labels[issue_id] << label
issue_labels[issue_id] << label if label.present?
end
issue_labels
......
......@@ -37,6 +37,23 @@ describe EE::Issuable do
expect(relation.labels_hash[issue_id]).to include('Feature', 'Second Label')
end
# This tests the workaround for the lack of a NOT NULL constraint in
# label_links.label_id:
# https://gitlab.com/gitlab-org/gitlab/issues/197307
context 'with a NULL label ID in the link' do
let(:issue) { create(:labeled_issue, labels: [feature_label, second_label]) }
before do
label_link = issue.label_links.find_by(label_id: second_label.id)
label_link.label_id = nil
label_link.save(validate: false)
end
it 'filters out bad labels' do
expect(Issue.where(id: issue.id).labels_hash[issue.id]).to match_array(['Feature'])
end
end
end
describe '#matches_cross_reference_regex?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment