diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-12-01 16:17:20 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-12-01 16:17:20 +0800 |
commit | 5747b0d3ed2a658a5a452e29aefba1aea5debc04 (patch) | |
tree | b1180aa8cea5b327d9ce4176fabd6c285b8c4527 /config | |
parent | bbcce5f7dcbc498bb82851f07be6d9a41578ea28 (diff) | |
download | gitlab-ce-5747b0d3ed2a658a5a452e29aefba1aea5debc04.tar.gz |
Make deleting with optimistic locking respect NULL
For now deleting with optimistic locking is broken when
lock_version is still NULL, because Rails would try to
delete with `lock_version = 0` while in the database
the column is still `NULL`.
The monkey patches would force Rails just pass whatever
in the column, and stop Rails from casting `NULL` into `0`
when the value is read from database.
Closes #24766
Diffstat (limited to 'config')
-rw-r--r-- | config/initializers/ar_monkey_patch.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/config/initializers/ar_monkey_patch.rb b/config/initializers/ar_monkey_patch.rb index 0da584626ee..5506873344f 100644 --- a/config/initializers/ar_monkey_patch.rb +++ b/config/initializers/ar_monkey_patch.rb @@ -52,6 +52,24 @@ module ActiveRecord raise end end + + # This is patched because we need it to query `lock_version IS NULL` + # rather than `lock_version = 0` whenever lock_version is NULL. + def relation_for_destroy + return super unless locking_enabled? + + column_name = self.class.locking_column + table_name = self.class.quoted_table_name + super.where("#{table_name}.#{column_name}" => self[column_name]) + end + end + + # This is patched because we want `lock_version` default to `NULL` + # rather than `0` + class LockingType < SimpleDelegator + def type_cast_from_database(value) + super + end end end end |