Commit 8686ab9c authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '240923-fix-foreign-key-violation' into 'master'

Fix ElasticCommitIndexerWorker FK violation

See merge request gitlab-org/gitlab!45249
parents 0be61da3 d9270f7a
---
title: Fix unnecessary Sidekiq errors/retries when project is deleted during indexing
merge_request: 45249
author:
type: fixed
......@@ -177,6 +177,15 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord
def update_index_status(to_sha)
unless Project.exists?(id: project.id)
Gitlab::Elasticsearch::Logger.build.debug(
message: 'Index status could not be updated as the project does not exist',
project_id: project.id,
wiki: index_wiki?
)
return false
end
raise "Invalid sha #{to_sha}" unless to_sha.present?
# An index_status should always be created,
......
......@@ -388,6 +388,25 @@ RSpec.describe Gitlab::Elastic::Indexer do
end
end
context 'when project no longer exists in database' do
let!(:logger_double) { instance_double(Gitlab::Elasticsearch::Logger) }
before do
allow(Gitlab::Elasticsearch::Logger).to receive(:build).and_return(logger_double)
allow(indexer).to receive(:run_indexer!) { Project.where(id: project.id).delete_all }
end
it 'does not raises an exception and prints log message' do
expect(logger_double).to receive(:debug).with(
message: 'Index status could not be updated as the project does not exist',
project_id: project.id,
wiki: false
)
expect(IndexStatus).not_to receive(:safe_find_or_create_by!).with(project_id: project.id)
expect { indexer.run }.not_to raise_error
end
end
def expect_popen
expect(Gitlab::Popen).to receive(:popen)
end
......
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