X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/fcb35ed42449c5ad58cd9ec62ff2ed353cf9d940..cbe594f580c26381d786d7b43d5227eb1d12620d:/services/api/app/controllers/application_controller.rb diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb index 7e5b316c2d..c9c78794d6 100644 --- a/services/api/app/controllers/application_controller.rb +++ b/services/api/app/controllers/application_controller.rb @@ -104,8 +104,11 @@ class ApplicationController < ActionController::Base if e.respond_to? :backtrace and e.backtrace logger.error e.backtrace.collect { |x| x + "\n" }.join('') end - if @object and @object.errors and @object.errors.full_messages and not @object.errors.full_messages.empty? + if (@object and @object.respond_to? :errors and + @object.errors and @object.errors.full_messages and + not @object.errors.full_messages.empty?) errors = @object.errors.full_messages + logger.error errors.inspect else errors = [e.inspect] end @@ -202,7 +205,17 @@ class ApplicationController < ActionController::Base end end - @objects = @objects.select(@select.map { |s| "#{table_name}.#{ActiveRecord::Base.connection.quote_column_name s.to_s}" }.join ", ") if @select + if @select + # Map attribute names in @select to real column names, resolve + # those to fully-qualified SQL column names, and pass the + # resulting string to the select method. + api_column_map = model_class.attributes_required_columns + columns_list = @select. + flat_map { |attr| api_column_map[attr] }. + uniq. + map { |s| "#{table_name}.#{ActiveRecord::Base.connection.quote_column_name s}" } + @objects = @objects.select(columns_list.join(", ")) + end @objects = @objects.order(@orders.join ", ") if @orders.any? @objects = @objects.limit(@limit) @objects = @objects.offset(@offset) @@ -351,6 +364,14 @@ class ApplicationController < ActionController::Base accept_param_as_json :reader_tokens, Array def render_list + if @select + # This information helps clients understand what they're seeing + # (Workbench always expects it), but they can't select it explicitly + # because it's not an SQL column. Always add it. + # I believe this is safe because clients can always deduce what they're + # looking at by the returned UUID anyway. + @select |= ["kind"] + end @object_list = { :kind => "arvados##{(@response_resource_name || resource_name).camelize(:lower)}List", :etag => "",