From 0fdc6533f4621a549a4cb99e778bbd827461a2d0 Mon Sep 17 00:00:00 2001 From: Fernando Briano Date: Wed, 25 Mar 2020 10:49:41 +0000 Subject: [PATCH] [Client] Change how the adapter is set in the client initializer Migrating to Faraday 1.0 means we check with `adapter` to see which one has been selected. I also changed the order in which the given block is ran. There's a case where one of the adapter libraries could be loaded and an adapter is passed in with the block, but `__auto_detect_adapter` would overwrite this. So the block is now ran last. --- .../lib/elasticsearch/transport/client.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/elasticsearch-transport/lib/elasticsearch/transport/client.rb b/elasticsearch-transport/lib/elasticsearch/transport/client.rb index 1d033d82ea..be61a6d54b 100644 --- a/elasticsearch-transport/lib/elasticsearch/transport/client.rb +++ b/elasticsearch-transport/lib/elasticsearch/transport/client.rb @@ -142,10 +142,8 @@ def initialize(arguments={}, &block) transport_class = @arguments[:transport_class] || DEFAULT_TRANSPORT_CLASS if transport_class == Transport::HTTP::Faraday @transport = transport_class.new(hosts: @seeds, options: @arguments) do |faraday| - block.call faraday if block - unless (h = faraday.builder.handlers.last) && h.name.start_with?("Faraday::Adapter") - faraday.adapter(@arguments[:adapter] || __auto_detect_adapter) - end + faraday.adapter(@arguments[:adapter] || __auto_detect_adapter) + block&.call faraday end else @transport = transport_class.new(hosts: @seeds, options: @arguments)