[ARVADOS] created: ea3c238d3d690f046aaf987f04132886a7ec0f56

Git user git at public.curoverse.com
Thu Sep 1 17:07:53 EDT 2016


        at  ea3c238d3d690f046aaf987f04132886a7ec0f56 (commit)


commit ea3c238d3d690f046aaf987f04132886a7ec0f56
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Sep 1 17:07:38 2016 -0400

    9875: Fix script_parameters_digest to sort hashes hiding inside arrays, too.

diff --git a/services/api/app/models/job.rb b/services/api/app/models/job.rb
index 248d16a..a86cc62 100644
--- a/services/api/app/models/job.rb
+++ b/services/api/app/models/job.rb
@@ -281,11 +281,16 @@ class Job < ArvadosModel
     Digest::MD5.hexdigest(Oj.dump(deep_sort_hash(h)))
   end
 
-  def self.deep_sort_hash h
-    return h unless h.is_a? Hash
-    h.sort.collect do |k, v|
-      [k, deep_sort_hash(v)]
-    end.to_h
+  def self.deep_sort_hash x
+    if x.is_a? Hash
+      x.sort.collect do |k, v|
+        [k, deep_sort_hash(v)]
+      end.to_h
+    elsif x.is_a? Array
+      x.collect { |v| deep_sort_hash(v) }
+    else
+      x
+    end
   end
 
   def foreign_key_attributes
diff --git a/services/api/db/migrate/20160901210110_repair_script_parameters_digest.rb b/services/api/db/migrate/20160901210110_repair_script_parameters_digest.rb
new file mode 100644
index 0000000..bdf881e
--- /dev/null
+++ b/services/api/db/migrate/20160901210110_repair_script_parameters_digest.rb
@@ -0,0 +1,17 @@
+class RepairScriptParametersDigest < ActiveRecord::Migration
+  def up
+    Job.find_each do |j|
+      have = j.script_parameters_digest
+      want = j.update_script_parameters_digest
+      if have != want
+        # where().update_all() skips validations, event logging, and
+        # timestamp updates, and just runs SQL. (This change is
+        # invisible to clients.)
+        Job.where('id=?', j.id).update_all(script_parameters_digest: j.script_parameters_digest)
+      end
+    end
+  end
+
+  def down
+  end
+end
diff --git a/services/api/db/structure.sql b/services/api/db/structure.sql
index bda4e5d..1573db2 100644
--- a/services/api/db/structure.sql
+++ b/services/api/db/structure.sql
@@ -2686,4 +2686,6 @@ INSERT INTO schema_migrations (version) VALUES ('20160808151559');
 
 INSERT INTO schema_migrations (version) VALUES ('20160819195557');
 
-INSERT INTO schema_migrations (version) VALUES ('20160819195725');
\ No newline at end of file
+INSERT INTO schema_migrations (version) VALUES ('20160819195725');
+
+INSERT INTO schema_migrations (version) VALUES ('20160901210110');
\ No newline at end of file
diff --git a/services/api/test/unit/job_test.rb b/services/api/test/unit/job_test.rb
index 1bc8035..1d3abac 100644
--- a/services/api/test/unit/job_test.rb
+++ b/services/api/test/unit/job_test.rb
@@ -456,4 +456,10 @@ class JobTest < ActiveSupport::TestCase
                    "wrong script_parameters_digest for #{j.uuid}")
     end
   end
+
+  test 'deep_sort_hash on array of hashes' do
+    a = {'z' => [[{'a' => 'a', 'b' => 'b'}]]}
+    b = {'z' => [[{'b' => 'b', 'a' => 'a'}]]}
+    assert_equal Job.deep_sort_hash(a).to_json, Job.deep_sort_hash(b).to_json
+  end
 end

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list