Commit d615759b authored by Stan Hu's avatar Stan Hu

Fix errors creating project with active Prometheus service template

If the Prometheus service template were active, the service would be
inserted into the database during project creation. Later, the call to
`Projects::CreateService#after_create_actions` might attempt to NULL out
the service if the project didn't have any clusters that needed the
service, but this would fail with a foreign key violation since this is
enforced by the database constraint.

To fix this, we just assume if the template is present that it should
be there and skip the whole active check.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/212419
parent 5a56f282
......@@ -173,6 +173,10 @@ module Projects
def create_prometheus_service
service = @project.find_or_initialize_service(::PrometheusService.to_param)
# If the service has already been inserted in the database, that
# means it came from a template, and there's nothing more to do.
return if service.persisted?
if service.prometheus_available?
service.save!
else
......
---
title: Fix errors creating project with active Prometheus service template
merge_request: 30340
author:
type: fixed
......@@ -348,6 +348,7 @@ describe Projects::CreateService, '#execute' do
project = create_project(user, opts)
expect(project.services.count).to eq 1
expect(project.errors).to be_empty
end
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