X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/b9fd7e3f374248a61159e4750a84e38d1c48d5dd..45cc809dfeab1d603e80cec3d44770d7f5a7c8ae:/services/api/app/models/collection.rb diff --git a/services/api/app/models/collection.rb b/services/api/app/models/collection.rb index caac5611e7..8b549a71ab 100644 --- a/services/api/app/models/collection.rb +++ b/services/api/app/models/collection.rb @@ -259,9 +259,10 @@ class Collection < ArvadosModel should_preserve_version = should_preserve_version? # Time sensitive, cache value return(yield) unless (should_preserve_version || syncable_updates.any?) - # Put aside the changes because with_lock forces a record reload + # Put aside the changes because with_lock does a record reload changes = self.changes snapshot = nil + restore_attributes with_lock do # Copy the original state to save it as old version if should_preserve_version @@ -303,12 +304,18 @@ class Collection < ArvadosModel def syncable_updates updates = {} - (syncable_attrs & self.changes.keys).each do |attr| + if self.changes.any? + changes = self.changes + else + # If called after save... + changes = self.saved_changes + end + (syncable_attrs & changes.keys).each do |attr| if attr == 'uuid' # Point old versions to current version's new UUID - updates['current_version_uuid'] = self.changes[attr].last + updates['current_version_uuid'] = changes[attr].last else - updates[attr] = self.changes[attr].last + updates[attr] = changes[attr].last end end return updates @@ -316,7 +323,7 @@ class Collection < ArvadosModel def sync_past_versions updates = self.syncable_updates - Collection.where('current_version_uuid = ? AND uuid != ?', self.uuid_was, self.uuid_was).each do |c| + Collection.where('current_version_uuid = ? AND uuid != ?', self.uuid_before_last_save, self.uuid_before_last_save).each do |c| c.attributes = updates # Use a different validation context to skip the 'past_versions_cannot_be_updated' # validator, as on this case it is legal to update some fields.