API returns 500 when sending "remove_source_branch: false" for MR creation and update
It's a minor bug that currently doesn't block users from creating MR's through the API with 'remove source branch' disabled by default (after https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11558 got merged). That's because sending remove_source_branch: false
is not necessary, since today we don't remove the source branch by default.
But, if an user tries to send remove_source_branch: false
, for whatever reason, this person would see a 500
, that's due to this particular line:
remove_source_branch
is removed from params only if it has a truthy value, which is not the case. So internally we try to create/update the MR with this get a 500
.
Report from https://gitlab.com/gitlab-org/gitlab-ce/issues/32823:
ActiveRecord::UnknownAttributeError (unknown attribute 'remove_source_branch' for MergeRequest.):
/opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/attribute_assignment.rb:59:in `rescue in _assign_attribute'
/opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
/opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
/opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/attribute_assignment.rb:35:in `each'
/opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
/opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/attr_encrypted-3.0.3/lib/attr_encrypted/adapters/active_record.rb:28:in `perform_attribute_assignment'
/opt/gitlab/embedded/lib/ruby/gems/2.3.0/gems/attr_encrypted-3.0.3/lib/attr_encrypted/adapters/active_record.rb:36:in `assign_attributes'
/opt/gitlab/embedded/service/gitlab-rails/app/services/issuable_base_service.rb:173:in `create'
/opt/gitlab/embedded/service/gitlab-rails/app/services/merge_requests/create_service.rb:16:in `execute'
Changing this line to the following might be enough to solve the issue:
mr_params[:force_remove_source_branch] = mr_params.delete(:remove_source_branch)
Note that sending remove_source_branch: false
to the API seems to never have worked before.