From 384312e9c149391e47578b91b16983405b7ad076 Mon Sep 17 00:00:00 2001 From: Vasilii Iakliushin Date: Mon, 11 Aug 2025 16:21:15 +0200 Subject: [PATCH] Handle missing project or user gracefully in CreatePipelineWorker **Problem** CreatePipelineWorker will fail when project or user are missing in database. **Solution** Gracefully stop the job if project or user are missing. Changelog: fixed --- app/workers/create_pipeline_worker.rb | 8 ++++++-- spec/workers/create_pipeline_worker_spec.rb | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/workers/create_pipeline_worker.rb b/app/workers/create_pipeline_worker.rb index f20d19a16378a1..52de68a04e3bac 100644 --- a/app/workers/create_pipeline_worker.rb +++ b/app/workers/create_pipeline_worker.rb @@ -17,8 +17,12 @@ class CreatePipelineWorker # rubocop:disable Scalability/IdempotentWorker def perform(project_id, user_id, ref, source, execute_options = {}, creation_params = {}) Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/464671') - project = Project.find(project_id) - user = User.find(user_id) + project = Project.find_by_id(project_id) + return unless project + + user = User.find_by_id(user_id) + return unless user + execute_options = execute_options.deep_symbolize_keys creation_params = creation_params.symbolize_keys.merge(ref: ref) diff --git a/spec/workers/create_pipeline_worker_spec.rb b/spec/workers/create_pipeline_worker_spec.rb index 5bdfc65c7253ea..866dd844f3d9d9 100644 --- a/spec/workers/create_pipeline_worker_spec.rb +++ b/spec/workers/create_pipeline_worker_spec.rb @@ -9,7 +9,7 @@ context 'when a project not found' do it 'does not call the Service' do expect(Ci::CreatePipelineService).not_to receive(:new) - expect { worker.perform(non_existing_record_id, create(:user).id, 'master', :web) }.to raise_error(ActiveRecord::RecordNotFound) + expect { worker.perform(non_existing_record_id, create(:user).id, 'master', :web) }.not_to raise_exception end end @@ -18,7 +18,7 @@ it 'does not call the Service' do expect(Ci::CreatePipelineService).not_to receive(:new) - expect { worker.perform(project.id, non_existing_record_id, project.default_branch, :web) }.to raise_error(ActiveRecord::RecordNotFound) + expect { worker.perform(project.id, non_existing_record_id, project.default_branch, :web) }.not_to raise_exception end end -- GitLab