[ARVADOS] updated: 463e996ae5276dc41deca98cb444c802e6f5e251

git at public.curoverse.com git at public.curoverse.com
Wed Jan 15 12:08:10 EST 2014


Summary of changes:
 .../api/app/controllers/application_controller.rb  |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

       via  463e996ae5276dc41deca98cb444c802e6f5e251 (commit)
      from  84f0a30a119355cd7deff1630a82d3d4c9a6d5ee (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 463e996ae5276dc41deca98cb444c802e6f5e251
Author: Tom Clegg <tom at curoverse.com>
Date:   Wed Jan 15 09:07:00 2014 -0800

    Reload the target object before updating if it is marked read-only
    (e.g., it was retrieved using a join). Also, fix error response when
    update is called on a non-existent object.
    
    Prevents ActiveRecord::ReadOnlyRecord error.
    
    refs #1871
    amends 92d1022d103b58ddad0427736a776a27f198667e

diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb
index 2b7b34b..f2d238a 100644
--- a/services/api/app/controllers/application_controller.rb
+++ b/services/api/app/controllers/application_controller.rb
@@ -11,6 +11,7 @@ class ApplicationController < ActionController::Base
   before_filter :load_where_param, :only => :index
   before_filter :find_objects_for_index, :only => :index
   before_filter :find_object_by_uuid, :except => [:index, :create]
+  before_filter :reload_object_before_update, :only => :update
 
   attr_accessor :resource_attrs
 
@@ -37,6 +38,9 @@ class ApplicationController < ActionController::Base
   end
 
   def update
+    if !@object
+      return render_not_found("object not found")
+    end
     attrs_to_update = resource_attrs.reject { |k,v|
       [:kind, :etag, :href].index k
     }
@@ -321,6 +325,14 @@ class ApplicationController < ActionController::Base
     @object = @objects.first
   end
 
+  def reload_object_before_update
+    # This is necessary to prevent an ActiveRecord::ReadOnlyRecord
+    # error when updating an object which was retrieved using a join.
+    if @object.andand.readonly?
+      @object = model_class.find(@objects.first.uuid)
+    end
+  end
+
   def self.accept_attribute_as_json(attr, force_class=nil)
     before_filter lambda { accept_attribute_as_json attr, force_class }
   end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list