Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
835c616b
Commit
835c616b
authored
May 06, 2019
by
Sean McGivern
Committed by
Mayra Cabrera
May 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix editing issues and MRs with NULL lock_version
parent
1309e180
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
0 deletions
+65
-0
config/initializers/config_initializers_active_record_locking.rb
...initializers/config_initializers_active_record_locking.rb
+41
-0
spec/models/issue_spec.rb
spec/models/issue_spec.rb
+12
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+12
-0
No files found.
config/initializers/config_initializers_active_record_locking.rb
0 → 100644
View file @
835c616b
# frozen_string_literal: true
# rubocop:disable Lint/RescueException
module
ActiveRecord
module
Locking
module
Optimistic
private
def
_update_row
(
attribute_names
,
attempted_action
=
"update"
)
return
super
unless
locking_enabled?
begin
locking_column
=
self
.
class
.
locking_column
previous_lock_value
=
read_attribute_before_type_cast
(
locking_column
)
attribute_names
<<
locking_column
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
affected_rows
=
self
.
class
.
unscoped
.
_update_record
(
arel_attributes_with_values
(
attribute_names
),
self
.
class
.
primary_key
=>
id_in_database
,
locking_column
=>
possible_previous_lock_value
)
if
affected_rows
!=
1
raise
ActiveRecord
::
StaleObjectError
.
new
(
self
,
attempted_action
)
end
affected_rows
# If something went wrong, revert the locking_column value.
rescue
Exception
self
[
locking_column
]
=
previous_lock_value
.
to_i
raise
end
end
end
end
end
spec/models/issue_spec.rb
View file @
835c616b
...
@@ -55,6 +55,18 @@ describe Issue do
...
@@ -55,6 +55,18 @@ describe Issue do
end
end
end
end
describe
'locking'
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'
)
expect
(
issue
.
reload
.
title
).
to
eq
(
'locking test'
)
end
end
describe
'#order_by_position_and_priority'
do
describe
'#order_by_position_and_priority'
do
let
(
:project
)
{
create
:project
}
let
(
:project
)
{
create
:project
}
let
(
:p1
)
{
create
(
:label
,
title:
'P1'
,
project:
project
,
priority:
1
)
}
let
(
:p1
)
{
create
(
:label
,
title:
'P1'
,
project:
project
,
priority:
1
)
}
...
...
spec/models/merge_request_spec.rb
View file @
835c616b
...
@@ -31,6 +31,18 @@ describe MergeRequest do
...
@@ -31,6 +31,18 @@ describe MergeRequest do
end
end
end
end
describe
'locking'
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'
)
expect
(
merge_request
.
reload
.
title
).
to
eq
(
'locking test'
)
end
end
describe
'#squash_in_progress?'
do
describe
'#squash_in_progress?'
do
let
(
:repo_path
)
do
let
(
:repo_path
)
do
Gitlab
::
GitalyClient
::
StorageSettings
.
allow_disk_access
do
Gitlab
::
GitalyClient
::
StorageSettings
.
allow_disk_access
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment