Skip to content

A platform for community discussion. Free, open, simple.

DEV: Handle `nil` keys in `SetStore` implementations

Gerhard Schlagerb7a1b3239519
diff --git a/migrations/lib/common/set_store/key_value_set.rb b/migrations/lib/common/set_store/key_value_set.rb
index e819fd11e5a..de0e6815d9e 100644
--- a/migrations/lib/common/set_store/key_value_set.rb
+++ b/migrations/lib/common/set_store/key_value_set.rb
@@ -23,7 +23,7 @@ module Migrations::SetStore
end
def bulk_add(records)
- current_key = nil
+ current_key = :__uninitialized__
current_set = nil
records.each do |record|
diff --git a/migrations/lib/common/set_store/simple_set.rb b/migrations/lib/common/set_store/simple_set.rb
index e776e6f53e4..e6eae11fd8c 100644
--- a/migrations/lib/common/set_store/simple_set.rb
+++ b/migrations/lib/common/set_store/simple_set.rb
@@ -29,5 +29,9 @@ module Migrations::SetStore
def empty?
@store.empty?
end
+
+ def each
+ @store.each
+ end
end
end
diff --git a/migrations/lib/common/set_store/three_key_set.rb b/migrations/lib/common/set_store/three_key_set.rb
index 7153f284c04..5bdcf08a607 100644
--- a/migrations/lib/common/set_store/three_key_set.rb
+++ b/migrations/lib/common/set_store/three_key_set.rb
@@ -31,9 +31,9 @@ module Migrations::SetStore
end
def bulk_add(records)
- current_key1 = nil
- current_key2 = nil
- current_key3 = nil
+ current_key1 = :__uninitialized__
+ current_key2 = :__uninitialized__
+ current_key3 = :__uninitialized__
current_h1 = nil
current_h2 = nil
current_set = nil
diff --git a/migrations/lib/common/set_store/two_key_set.rb b/migrations/lib/common/set_store/two_key_set.rb
index e3add6e47e4..c2ca1168a84 100644
--- a/migrations/lib/common/set_store/two_key_set.rb
+++ b/migrations/lib/common/set_store/two_key_set.rb
@@ -28,8 +28,8 @@ module Migrations::SetStore
end
def bulk_add(records)
- current_key1 = nil
- current_key2 = nil
+ current_key1 = :__uninitialized__
+ current_key2 = :__uninitialized__
current_h1 = nil
current_set = nil
diff --git a/migrations/spec/lib/common/set_store/key_value_set_spec.rb b/migrations/spec/lib/common/set_store/key_value_set_spec.rb
index ab1faed2909..54174740ae5 100644
--- a/migrations/spec/lib/common/set_store/key_value_set_spec.rb
+++ b/migrations/spec/lib/common/set_store/key_value_set_spec.rb
@@ -54,6 +54,13 @@ describe Migrations::SetStore::KeyValueSet do
expect(set.include?("key2", 2)).to be true
end
+ it "handles nil keys correctly" do
+ set.bulk_add([[nil, 1], [nil, 2], ["key1", 3]])
+ expect(set.include?(nil, 1)).to be true
+ expect(set.include?(nil, 2)).to be true
+ expect(set.include?("key1", 3)).to be true
+ end
+
it "returns nil" do
expect(set.bulk_add([["key1", 1]])).to be_nil
end
diff --git a/migrations/spec/lib/common/set_store/three_key_set_spec.rb b/migrations/spec/lib/common/set_store/three_key_set_spec.rb
index 131e9182529..d68086cdd43 100644
--- a/migrations/spec/lib/common/set_store/three_key_set_spec.rb
+++ b/migrations/spec/lib/common/set_store/three_key_set_spec.rb
@@ -73,6 +73,13 @@ describe Migrations::SetStore::ThreeKeySet do
expect(set.include?("key4", "key5", "key6", 2)).to be true
end
+ it "handles nil keys correctly" do
+ set.bulk_add([[nil, "key2", "key3", 1], ["key1", nil, "key3", 2], ["key1", "key2", nil, 3]])
+ expect(set.include?(nil, "key2", "key3", 1)).to be true
+ expect(set.include?("key1", nil, "key3", 2)).to be true
+ expect(set.include?("key1", "key2", nil, 3)).to be true
+ end
+
it "returns nil" do
expect(set.bulk_add([["key1", "key2", "key3", 1]])).to be_nil
end
diff --git a/migrations/spec/lib/common/set_store/two_key_set_spec.rb b/migrations/spec/lib/common/set_store/two_key_set_spec.rb
index 7a9b6600a5f..583b75756b9 100644
--- a/migrations/spec/lib/common/set_store/two_key_set_spec.rb
+++ b/migrations/spec/lib/common/set_store/two_key_set_spec.rb
@@ -66,6 +66,13 @@ describe Migrations::SetStore::TwoKeySet do
expect(set.include?("key3", "key4", 2)).to be true
end
+ it "handles nil keys correctly" do
+ set.bulk_add([[nil, "key2", 1], [nil, "key3", 2], ["key1", nil, 3]])
+ expect(set.include?(nil, "key2", 1)).to be true
+ expect(set.include?(nil, "key3", 2)).to be true
+ expect(set.include?("key1", nil, 3)).to be true
+ end
+
it "returns nil" do
expect(set.bulk_add([["key1", "key2", 1]])).to be_nil
end