Commit 88e3b8ec authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '44922-fix-build-metadata-creation' into 'master'

Resolve "ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_ci_builds_meta..."

Closes #44922

See merge request gitlab-org/gitlab-ce!18155
parents cb5bb4db 11204398
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
return `#${this.job.runner.id}`; return `#${this.job.runner.id}`;
}, },
hasTimeout() { hasTimeout() {
return this.job.metadata != null && this.job.metadata.timeout_human_readable !== ''; return this.job.metadata != null && this.job.metadata.timeout_human_readable !== null;
}, },
timeout() { timeout() {
if (this.job.metadata == null) { if (this.job.metadata == null) {
......
...@@ -90,6 +90,7 @@ module Ci ...@@ -90,6 +90,7 @@ module Ci
before_save :ensure_token before_save :ensure_token
before_destroy { unscoped_project } before_destroy { unscoped_project }
before_create :ensure_metadata
after_create unless: :importing? do |build| after_create unless: :importing? do |build|
run_after_commit { BuildHooksWorker.perform_async(build.id) } run_after_commit { BuildHooksWorker.perform_async(build.id) }
end end
......
class BuildMetadataEntity < Grape::Entity class BuildMetadataEntity < Grape::Entity
expose :timeout_human_readable do |metadata| expose :timeout_human_readable
metadata.timeout_human_readable unless metadata.timeout.nil?
end
expose :timeout_source do |metadata| expose :timeout_source do |metadata|
metadata.present.timeout_source metadata.present.timeout_source
end end
......
FactoryBot.define do
factory :ci_build_metadata, class: Ci::BuildMetadata do
build factory: :ci_build
after(:build) do |build_metadata, _|
build_metadata.project ||= build_metadata.build.project
end
end
end
...@@ -13,7 +13,7 @@ describe Ci::BuildMetadata do ...@@ -13,7 +13,7 @@ describe Ci::BuildMetadata do
end end
let(:build) { create(:ci_build, pipeline: pipeline) } let(:build) { create(:ci_build, pipeline: pipeline) }
let(:build_metadata) { create(:ci_build_metadata, build: build) } let(:build_metadata) { build.metadata }
describe '#update_timeout_state' do describe '#update_timeout_state' do
subject { build_metadata } subject { build_metadata }
......
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