summaryrefslogtreecommitdiff
path: root/app/models/concerns/project_api_compatibility.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-07-19 21:39:26 +0000
committerMayra Cabrera <mcabrera@gitlab.com>2019-07-19 21:39:26 +0000
commita5a444906de6372105c41260a9b1c1eb49d4dc9e (patch)
tree36a27006da6e7da943804400e6c08fd3d87bb76a /app/models/concerns/project_api_compatibility.rb
parenteb3f465e75ee1fc5ef582e9f01f921626d7cf5cc (diff)
downloadgitlab-ce-a5a444906de6372105c41260a9b1c1eb49d4dc9e.tar.gz
Fix the project auto devops API
If `project_auto_devops.enabled` is nil for a project, when setting any auto devops values via the API, we try to create a new row in the DB, instead of re-using the existing one. This leads to the project_id being set to nil, and the database `NOT NULL` constraint leading to a 500 response. This commit resolves the issue by correctly detecting the presence of a ProjectAutoDevops row and re-using it. Persistence is also moved away from explicit `update!` calls and into relying on `autosave: true` on the model.
Diffstat (limited to 'app/models/concerns/project_api_compatibility.rb')
-rw-r--r--app/models/concerns/project_api_compatibility.rb6
1 files changed, 2 insertions, 4 deletions
diff --git a/app/models/concerns/project_api_compatibility.rb b/app/models/concerns/project_api_compatibility.rb
index cb00efb06df..631b2a11e9a 100644
--- a/app/models/concerns/project_api_compatibility.rb
+++ b/app/models/concerns/project_api_compatibility.rb
@@ -9,12 +9,10 @@ module ProjectAPICompatibility
end
def auto_devops_enabled=(value)
- self.build_auto_devops if self.auto_devops&.enabled.nil?
- self.auto_devops.update! enabled: value
+ (auto_devops || build_auto_devops).enabled = value
end
def auto_devops_deploy_strategy=(value)
- self.build_auto_devops if self.auto_devops&.enabled.nil?
- self.auto_devops.update! deploy_strategy: value
+ (auto_devops || build_auto_devops).deploy_strategy = value
end
end