diff --git a/lib/banzai/reference_parser/base_parser.rb b/lib/banzai/reference_parser/base_parser.rb
index 8419769085ae2b519991bfed2de3e8dd457c497f..9160c0e14cfefe663fe713fa619661412819790e 100644
--- a/lib/banzai/reference_parser/base_parser.rb
+++ b/lib/banzai/reference_parser/base_parser.rb
@@ -177,7 +177,7 @@ module Banzai
             collection.where(id: to_query).each { |row| cache[row.id] = row }
           end
 
-          cache.values_at(*ids).compact
+          ids.uniq.map { |id| cache[id] }.compact
         else
           collection.where(id: ids)
         end
diff --git a/spec/lib/banzai/reference_parser/base_parser_spec.rb b/spec/lib/banzai/reference_parser/base_parser_spec.rb
index 7897164d985290c3b20f8171ae3a55706b568c2d..b1002c1db254688c2f8da09bd4a712232e1dbd0d 100644
--- a/spec/lib/banzai/reference_parser/base_parser_spec.rb
+++ b/spec/lib/banzai/reference_parser/base_parser_spec.rb
@@ -312,6 +312,12 @@ describe Banzai::ReferenceParser::BaseParser do
         expect(subject.collection_objects_for_ids(Project, [project.id]))
           .to eq([project])
       end
+
+      it 'will not overflow the stack' do
+        ids = 1.upto(1_000_000).to_a
+
+        expect { subject.collection_objects_for_ids(User, ids) }.not_to raise_error
+      end
     end
   end