[ARVADOS] updated: 62481e29ad90ca0014574bb0f863b27cd93441a8

Git user git at public.curoverse.com
Thu Sep 1 22:12:00 EDT 2016


Summary of changes:
 .../api/db/migrate/20160901210110_repair_script_parameters_digest.rb    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

  discards  ea3c238d3d690f046aaf987f04132886a7ec0f56 (commit)
       via  62481e29ad90ca0014574bb0f863b27cd93441a8 (commit)

This update added new revisions after undoing existing revisions.  That is
to say, the old revision is not a strict subset of the new revision.  This
situation occurs when you --force push a change and generate a repository
containing something like this:

 * -- * -- B -- O -- O -- O (ea3c238d3d690f046aaf987f04132886a7ec0f56)
            \
             N -- N -- N (62481e29ad90ca0014574bb0f863b27cd93441a8)

When this happens we assume that you've already had alert emails for all
of the O revisions, and so we here report only the revisions in the N
branch from the common base, B.

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 62481e29ad90ca0014574bb0f863b27cd93441a8
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Sep 1 22:05:51 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..18eed7a
--- /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: want)
+      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