X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1e803e86b1ba69b9770192a9cf1e66edb125cf1d..9c656c55fe63a22b075223fe7f295e7e21e18b8c:/apps/workbench/app/models/arvados_base.rb diff --git a/apps/workbench/app/models/arvados_base.rb b/apps/workbench/app/models/arvados_base.rb index 9925d46128..b9162c2aec 100644 --- a/apps/workbench/app/models/arvados_base.rb +++ b/apps/workbench/app/models/arvados_base.rb @@ -104,11 +104,11 @@ class ArvadosBase attributes.symbolize_keys.each do |name, value| send("#{name}=", value) end -end + end def self.columns + @discovered_columns = [] if !defined?(@discovered_columns) return @discovered_columns if @discovered_columns.andand.any? - @discovered_columns = [] @attribute_info ||= {} schema = arvados_api_client.discovery[:schemas][self.to_s.to_sym] return @discovered_columns if schema.nil? @@ -123,7 +123,6 @@ end else # Hash, Array @discovered_columns << column(k, coldef[:type], coldef[:type].constantize.new) - # serialize k, coldef[:type].constantize end attr_reader k @attribute_info[k] = coldef @@ -133,7 +132,14 @@ end end def new_record? - (uuid == nil) ? true : false + # dup method doesn't reset the uuid attr + @uuid.nil? || @new_record || false + end + + def initialize_dup(other) + super + @new_record = true + @created_at = nil end def self.column(name, sql_type = nil, default = nil, null = true) @@ -152,6 +158,8 @@ end ArvadosBase::Type::Hash when 'Array' ArvadosBase::Type::Array + when 'jsonb' + ArvadosBase::Type::Hash else raise ArvadosBase::Error.new("Type unknown: #{sql_type}") end @@ -172,6 +180,7 @@ end begin send(attr_name) rescue + Rails.logger.debug "BUG: access non-loaded attribute #{attr_name}" nil end end @@ -316,7 +325,10 @@ end obdata.delete :uuid resp = arvados_api_client.api(self.class, '/' + uuid, postdata) else - postdata.merge!(@create_params) if @create_params + if @create_params + @create_params = @create_params.to_unsafe_hash if @create_params.is_a? ActionController::Parameters + postdata.merge!(@create_params) + end resp = arvados_api_client.api(self.class, '', postdata) end return false if !resp[:etag] || !resp[:uuid] @@ -347,7 +359,7 @@ end end def destroyed? - !(etag || uuid) + !(new_record? || etag || uuid) end def destroy @@ -527,17 +539,17 @@ end if opts[:class].is_a? Class return opts[:class] end - if uuid.match /^[0-9a-f]{32}(\+[^,]+)*(,[0-9a-f]{32}(\+[^,]+)*)*$/ + if uuid.match(/^[0-9a-f]{32}(\+[^,]+)*(,[0-9a-f]{32}(\+[^,]+)*)*$/) return Collection end resource_class = nil - uuid.match /^[0-9a-z]{5}-([0-9a-z]{5})-[0-9a-z]{15}$/ do |re| + uuid.match(/^[0-9a-z]{5}-([0-9a-z]{5})-[0-9a-z]{15}$/) do |re| resource_class ||= arvados_api_client. kind_class(self.uuid_infix_object_kind[re[1]]) end if opts[:referring_object] and opts[:referring_attr] and - opts[:referring_attr].match /_uuid$/ + opts[:referring_attr].match(/_uuid$/) resource_class ||= arvados_api_client. kind_class(opts[:referring_object]. attributes[opts[:referring_attr].