diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-04-04 19:07:13 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-04-04 19:07:13 +0000 |
commit | 88e3b8ec271d9624371ee71eb16e7476f00c9bc3 (patch) | |
tree | 3372aee22aeece4426fc34eb606207c190f618cd | |
parent | cb5bb4dbc67c5dd43bb7b27faf79ca79f8ae3e1f (diff) | |
parent | 11204398fbbd044ca587bb1b082ffbc1eaac2738 (diff) | |
download | gitlab-ce-88e3b8ec271d9624371ee71eb16e7476f00c9bc3.tar.gz |
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
-rw-r--r-- | app/assets/javascripts/jobs/components/sidebar_details_block.vue | 2 | ||||
-rw-r--r-- | app/models/ci/build.rb | 1 | ||||
-rw-r--r-- | app/serializers/build_metadata_entity.rb | 5 | ||||
-rw-r--r-- | spec/factories/ci/build_metadata.rb | 9 | ||||
-rw-r--r-- | spec/models/ci/build_metadata_spec.rb | 2 |
5 files changed, 4 insertions, 15 deletions
diff --git a/app/assets/javascripts/jobs/components/sidebar_details_block.vue b/app/assets/javascripts/jobs/components/sidebar_details_block.vue index 172de6b3679..af47056d98f 100644 --- a/app/assets/javascripts/jobs/components/sidebar_details_block.vue +++ b/app/assets/javascripts/jobs/components/sidebar_details_block.vue @@ -45,7 +45,7 @@ return `#${this.job.runner.id}`; }, 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() { if (this.job.metadata == null) { diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 18e96389199..4aa65bf4273 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -90,6 +90,7 @@ module Ci before_save :ensure_token before_destroy { unscoped_project } + before_create :ensure_metadata after_create unless: :importing? do |build| run_after_commit { BuildHooksWorker.perform_async(build.id) } end diff --git a/app/serializers/build_metadata_entity.rb b/app/serializers/build_metadata_entity.rb index 39f429aa6c3..f16f3badffa 100644 --- a/app/serializers/build_metadata_entity.rb +++ b/app/serializers/build_metadata_entity.rb @@ -1,8 +1,5 @@ class BuildMetadataEntity < Grape::Entity - expose :timeout_human_readable do |metadata| - metadata.timeout_human_readable unless metadata.timeout.nil? - end - + expose :timeout_human_readable expose :timeout_source do |metadata| metadata.present.timeout_source end diff --git a/spec/factories/ci/build_metadata.rb b/spec/factories/ci/build_metadata.rb deleted file mode 100644 index 66bbd977b88..00000000000 --- a/spec/factories/ci/build_metadata.rb +++ /dev/null @@ -1,9 +0,0 @@ -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 diff --git a/spec/models/ci/build_metadata_spec.rb b/spec/models/ci/build_metadata_spec.rb index 268561ee941..7e75d5a5411 100644 --- a/spec/models/ci/build_metadata_spec.rb +++ b/spec/models/ci/build_metadata_spec.rb @@ -13,7 +13,7 @@ describe Ci::BuildMetadata do end 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 subject { build_metadata } |