Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2018-12-27 17:46:57 +0300
committerDouwe Maan <douwe@selenight.nl>2018-12-27 17:59:19 +0300
commit82370345302426c9d854e78c2a32a56ab4eb6c47 (patch)
tree38447a22b8aeafab9e69ac70e6d6d1712e0a38c9 /config/initializers
parentfd27be93489d7485754895ffef161431bf268b3d (diff)
Support both 0 and NULL lock_versions
Diffstat (limited to 'config/initializers')
-rw-r--r--config/initializers/active_record_locking.rb8
1 files changed, 2 insertions, 6 deletions
diff --git a/config/initializers/active_record_locking.rb b/config/initializers/active_record_locking.rb
index b8e8a0427e5..1bd1a12e4b7 100644
--- a/config/initializers/active_record_locking.rb
+++ b/config/initializers/active_record_locking.rb
@@ -19,12 +19,7 @@ module ActiveRecord
return 0 if attribute_names.empty?
lock_col = self.class.locking_column
-
previous_lock_value = send(lock_col).to_i
-
- # This line is added as a patch
- previous_lock_value = nil if previous_lock_value == '0' || previous_lock_value == 0
-
increment_lock
attribute_names += [lock_col]
@@ -35,7 +30,8 @@ module ActiveRecord
affected_rows = relation.where(
self.class.primary_key => id,
- lock_col => previous_lock_value
+ # Patched because when `lock_version` is read as `0`, it may actually be `NULL` in the DB.
+ lock_col => previous_lock_value == 0 ? [nil, 0] : previous_lock_value
).update_all(
attributes_for_update(attribute_names).map do |name|
[name, _read_attribute(name)]