Skip to content
Snippets Groups Projects
Verified Commit d93be3b1 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin :two: Committed by GitLab
Browse files

Fix missing `ci_cd_settings` relation on project creation

Contributes to #421050

**Problem**

Relation `ci_cd_settings` is automatically created for every new
project. But it only works if this relation was not touched during
project creation flow.

`group_runners_enabled` field is delegated to `ci_cd_settings`. When
user passes `group_runners_enabled` to the `Projects::CreateService`, it
initializes `ci_cd_settings` relation with a `nil` value. Because of
that, when the project is saved this relation doesn't create a record in
`ci_cd_settings` table.

**Solution**

Explicitly `build` an association for `ci_cd_settings` if it's missing.

Changelog: fixed
parent 17638f97
No related branches found
No related tags found
1 merge request!164094Fix missing `ci_cd_settings` relation on project creation
......@@ -35,7 +35,12 @@ def execute
return ::Projects::CreateFromTemplateService.new(current_user, params).execute
end
@project = Project.new(params.merge(creator: current_user))
@project = Project.new.tap do |p|
# Explicitly build an association for ci_cd_settings
# See: https://gitlab.com/gitlab-org/gitlab/-/issues/421050
p.build_ci_cd_settings
p.assign_attributes(params.merge(creator: current_user))
end
if @import_export_upload
@import_export_upload.project = project
......
......@@ -1295,6 +1295,17 @@ def create_project(user, opts)
end
end
context 'with group_runners_enabled' do
subject(:project) { create_project(user, opts) }
let(:opts) { super().merge(group_runners_enabled: true) }
it 'creates ci_cd_settings relation' do
expect(project.ci_cd_settings).to be_present
expect(project.ci_cd_settings.group_runners_enabled).to be_truthy
end
end
context 'when using access_level params' do
def expect_not_disabled_features(project, exclude: [])
ProjectFeature::FEATURES.excluding(exclude)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment