Skip to content

Commit 0f3ba42

Browse files
jnunemakerclaude
andcommitted
Fix serialization error when caching get_all results
Remove default_proc from result hashes in active_record, mongo, and sequel adapters before returning from get_all. The default_proc is used as a convenience during hash construction but prevents Marshal.dump serialization when results are cached by ActiveSupportCacheStore. Co-Authored-By: Claude Haiku 4.5 <[email protected]>
1 parent 185c76b commit 0f3ba42

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

lib/flipper/adapters/active_record.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def get_all(**kwargs)
123123
features.each do |feature|
124124
result[feature.key] = result_for_gates(feature, grouped_gates[feature.key])
125125
end
126+
result.default_proc = nil
126127
result
127128
end
128129
end

lib/flipper/adapters/mongo.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def read_many_features(features)
129129
docs = find_many(features.map(&:key))
130130
result = {}
131131
features.each do |feature|
132-
result[feature.key] = result_for_feature(feature, docs[feature.key])
132+
result[feature.key] = result_for_feature(feature, docs.fetch(feature.key, {}))
133133
end
134134
result
135135
end
@@ -146,7 +146,7 @@ def find(key)
146146

147147
def find_many(keys)
148148
docs = @collection.find(_id: { '$in' => keys }).to_a
149-
result = Hash.new { |hash, key| hash[key] = {} }
149+
result = {}
150150
docs.each do |doc|
151151
result[doc['_id']] = doc
152152
end

lib/flipper/adapters/sequel.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def get_all(**kwargs)
117117
features.each do |feature|
118118
result[feature.key] = result_for_feature(feature, grouped_db_gates[feature.key])
119119
end
120+
result.default_proc = nil
120121
result
121122
end
122123

0 commit comments

Comments
 (0)