Commit 4e50a22a authored by Robert Speicher's avatar Robert Speicher

Merge branch '214998-fix-null-deref' into 'master'

Fix null dereference in project_import_status

Closes #214998

See merge request gitlab-org/gitlab!29886
parents 0a4c1ce4 ffb32dad
---
title: Fix null dereference in /import status REST endpoint
merge_request: 29886
author:
type: fixed
......@@ -9,7 +9,7 @@ module API
end
expose :failed_relations, using: Entities::ProjectImportFailedRelation do |project, _options|
project.import_state.relation_hard_failures(limit: 100)
project.import_state&.relation_hard_failures(limit: 100) || []
end
# TODO: Use `expose_nil` once we upgrade the grape-entity gem
......
......@@ -8,6 +8,17 @@ describe API::Entities::ProjectImportStatus do
let(:correlation_id) { 'cid' }
context 'when no import state exists' do
let(:entity) { described_class.new(build(:project)) }
it 'includes basic fields and no failures' do
expect(subject[:import_status]).to eq('none')
expect(subject[:correlation_id]).to be_nil
expect(subject[:import_error]).to be_nil
expect(subject[:failed_relations]).to eq([])
end
end
context 'when import has not finished yet' do
let(:project) { create(:project, :import_scheduled, import_correlation_id: correlation_id) }
let(:entity) { described_class.new(project) }
......
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