Skip to content
代码片段 群组 项目
提交 c2dde812 编辑于 作者: Dylan Griffith's avatar Dylan Griffith
浏览文件

Ensure ci_pipelines.iid set before transaction in commit status API

Prior to this we were using `create!` which triggered the
`ensure_project_iid!` in a callback. This causes a
`CrossDatabaseModificationAcrossUnsupportedTablesError`. To avoid this
we will create the `iid` before saving. This is consistent with all
other places we create pipelines.

This change still doesn't allow us to remove
`spec/requests/api/commit_statuses_spec.rb` from the allowlist as there
are other calls to `project.ci_pipelines.create!` in this file.

We need a more holistic solution for that which is being discussed in
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/75316 .
上级 b18bfee3
No related branches found
No related tags found
无相关合并请求
...@@ -78,13 +78,16 @@ class CommitStatuses < ::API::Base ...@@ -78,13 +78,16 @@ class CommitStatuses < ::API::Base
name = params[:name] || params[:context] || 'default' name = params[:name] || params[:context] || 'default'
pipeline ||= user_project.ci_pipelines.create!( pipeline ||= user_project.ci_pipelines.build(
source: :external, source: :external,
sha: commit.sha, sha: commit.sha,
ref: ref, ref: ref,
user: current_user, user: current_user,
protected: user_project.protected_for?(ref)) protected: user_project.protected_for?(ref))
pipeline.ensure_project_iid!
pipeline.save!
authorize! :update_pipeline, pipeline authorize! :update_pipeline, pipeline
status = GenericCommitStatus.running_or_pending.find_or_initialize_by( status = GenericCommitStatus.running_or_pending.find_or_initialize_by(
......
...@@ -131,7 +131,7 @@ def create_status(commit, opts = {}) ...@@ -131,7 +131,7 @@ def create_status(commit, opts = {})
%w[pending running success failed canceled].each do |status| %w[pending running success failed canceled].each do |status|
context "for #{status}" do context "for #{status}" do
context 'when pipeline for sha does not exists' do context 'when pipeline for sha does not exists' do
it 'creates commit status' do it 'creates commit status and sets pipeline iid' do
post api(post_url, developer), params: { state: status } post api(post_url, developer), params: { state: status }
expect(response).to have_gitlab_http_status(:created) expect(response).to have_gitlab_http_status(:created)
...@@ -145,6 +145,8 @@ def create_status(commit, opts = {}) ...@@ -145,6 +145,8 @@ def create_status(commit, opts = {})
if status == 'failed' if status == 'failed'
expect(CommitStatus.find(json_response['id'])).to be_api_failure expect(CommitStatus.find(json_response['id'])).to be_api_failure
end end
expect(::Ci::Pipeline.last.iid).not_to be_nil
end end
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册