Commit b7b852c2 authored by Stan Hu's avatar Stan Hu

Additional fix to handle NULL lock_version

If the UI sends a string value for lock_version (e.g. "0"), then the
previous monkey patch did not properly handle that properly. This
commit casts the value to an integer to determine whether to look for
NULL lock_versions.

For merge requests, GitLab sends a POST request to
`namespace/project/merge_requests/:iid` with the
`merge_request[lock_version]` parameter with a string `0`. The string
value comes from the form field, which explains why
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/28145 wasn't
sufficient.
parent e1aa7f50
# frozen_string_literal: true
# ensure ActiveRecord's version has been required already
require 'active_record/locking/optimistic'
# rubocop:disable Lint/RescueException
module ActiveRecord
module Locking
......@@ -16,7 +20,7 @@ module ActiveRecord
self[locking_column] += 1
# Patched because when `lock_version` is read as `0`, it may actually be `NULL` in the DB.
possible_previous_lock_value = previous_lock_value == 0 ? [nil, 0] : previous_lock_value
possible_previous_lock_value = previous_lock_value.to_i == 0 ? [nil, 0] : previous_lock_value
affected_rows = self.class.unscoped._update_record(
arel_attributes_with_values(attribute_names),
......
......@@ -56,16 +56,27 @@ describe Issue do
end
describe 'locking' do
using RSpec::Parameterized::TableSyntax
where(:lock_version) do
[
[0],
["0"]
]
end
with_them do
it 'works when an issue has a NULL lock_version' do
issue = create(:issue)
described_class.where(id: issue.id).update_all('lock_version = NULL')
issue.update!(lock_version: 0, title: 'locking test')
issue.update!(lock_version: lock_version, title: 'locking test')
expect(issue.reload.title).to eq('locking test')
end
end
end
describe '#order_by_position_and_priority' do
let(:project) { create :project }
......
......@@ -32,16 +32,27 @@ describe MergeRequest do
end
describe 'locking' do
using RSpec::Parameterized::TableSyntax
where(:lock_version) do
[
[0],
["0"]
]
end
with_them do
it 'works when a merge request has a NULL lock_version' do
merge_request = create(:merge_request)
described_class.where(id: merge_request.id).update_all('lock_version = NULL')
merge_request.update!(lock_version: 0, title: 'locking test')
merge_request.update!(lock_version: lock_version, title: 'locking test')
expect(merge_request.reload.title).to eq('locking test')
end
end
end
describe '#squash_in_progress?' do
let(:repo_path) do
......
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