Skip to content

Commit 5f01257

Browse files
authored
Merge pull request #13485 from demarche-numerique/fix_openstack_bulk_delete_patch
Tech: corrige la correction (!) de fog delete_mutliple_object
2 parents 09a8406 + 4fb8cb5 commit 5f01257

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

config/initializers/active_storage.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,16 @@ def publicize(url)
161161
# same escaping rules, and it keeps the `container/object` slash literal (unlike
162162
# `ERB::Util.url_encode`, which would encode it and break the path).
163163
#
164+
# We PREPEND a module rather than reopen the class: fog requires the original request
165+
# file lazily, on the first `Fog::OpenStack::Storage.new` (setup_requirements ->
166+
# require_requests_and_mock), which happens AFTER this initializer. A class reopen
167+
# would then be redefined (clobbered) by that require; a prepended module stays ahead
168+
# of Real in the ancestor chain and wins whatever the load order.
169+
#
164170
# https://github.com/fog/fog-openstack/blob/v1.1.5/lib/fog/openstack/storage/requests/delete_multiple_objects.rb
165171
require 'fog/openstack'
166172

167-
class Fog::OpenStack::Storage::Real
173+
module OpenStackBulkDeletePatch
168174
def delete_multiple_objects(container, object_names, options = {})
169175
body = object_names.map do |name|
170176
object_name = container ? "#{container}/#{name}" : name
@@ -182,3 +188,5 @@ def delete_multiple_objects(container, object_names, options = {})
182188
response
183189
end
184190
end
191+
192+
Fog::OpenStack::Storage::Real.prepend(OpenStackBulkDeletePatch)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe 'delete_multiple_objects bulk-delete patch' do
6+
# fog requires its original delete_multiple_objects (with the Ruby-3.0-removed
7+
# URI.encode) lazily, on the first client instantiation — after our initializer.
8+
# A prepended module stays ahead of Real in the ancestor chain, so it wins whatever
9+
# the load order; a plain class reopen would be clobbered (owner back to Real).
10+
it 'keeps the prepended patch ahead of the fog original' do
11+
expect(Fog::OpenStack::Storage::Real.instance_method(:delete_multiple_objects).owner)
12+
.to eq(OpenStackBulkDeletePatch)
13+
end
14+
end

0 commit comments

Comments
 (0)