-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add explicit dependency on faraday #13
Comments
I can confirm that if I order my Gemfile to put faraday-net_http_persistent before faraday, this leads to a crash. gem "faraday-net_http_persistent"
gem "faraday"
This seems quite fragile! |
Thank you both for reporting, I'm taking a closer look. |
Ok, a bit of history:
Based on this, I'd assume the decision of not having Faraday as a dependency was mostly in support to those running Faraday 1.9.0 or prior, since the gemspec there allowed to load v2 of these gems. In fact, this is not a problem in other adapter gems (e.g. excon). The only way I can think of to fix this that doesn't affect people running Faraday 1.9 or prior, is to release a new v3 of these adapter gems that adds a dependency on @olbrich @mattbrictson what do you think, would that work for you or am I missing something obvious? |
Wow, history is more complicated that I realized! Backwards compatibility is really tricky. What if we added diff --git lib/faraday/net_http_persistent.rb lib/faraday/net_http_persistent.rb
index 895a3b7..a7792b8 100644
--- lib/faraday/net_http_persistent.rb
+++ lib/faraday/net_http_persistent.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
+require "faraday"
require_relative "adapter/net_http_persistent"
require_relative "net_http_persistent/version"
|
IIRC that breaks because Faraday 1.x requires the adapters and this causes a require loop
It is, I suffered unspeakable pain earlier this year because of this and tried to forget 🙈, but it keeps hunting me |
Would this work? diff --git lib/faraday/net_http_persistent.rb lib/faraday/net_http_persistent.rb
index 895a3b7..49df7ea 100644
--- lib/faraday/net_http_persistent.rb
+++ lib/faraday/net_http_persistent.rb
@@ -12,6 +12,7 @@ module Faraday
# * conn.adapter Faraday::Adapter::NetNttpPersistent
# * conn.adapter :net_http_persistent
# Without this line, only the former method is valid.
+ require "faraday" unless defined?(Faraday::Adapter) && Faraday::Adapter.respond_to?(:register_middleware)
Faraday::Adapter.register_middleware(net_http_persistent: Faraday::Adapter::NetHttpPersistent)
end
end |
I can give it a try, though once you hit the require on that line (i.e. if |
Here are are the scenarios: gem "faraday", "~> 1.0"
gem "faraday-net_http_persistent" ✅ OK gem "faraday-net_http_persistent"
gem "faraday", "~> 1.0" ❌ gems/faraday-net_http-2.1.0/lib/faraday/net_http.rb:8:in gem "faraday", "~> 2.0"
gem "faraday-net_http_persistent" ✅ OK gem "faraday-net_http_persistent"
gem "faraday", "~> 2.0" ❌ gems/faraday-net_http-2.1.0/lib/faraday/net_http.rb:8:in If I apply the following patch: diff --git lib/faraday/net_http_persistent.rb lib/faraday/net_http_persistent.rb
index 895a3b7..c609176 100644
--- lib/faraday/net_http_persistent.rb
+++ lib/faraday/net_http_persistent.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
+require "faraday" unless defined?(Faraday::Adapter) && Faraday::Adapter.respond_to?(:register_middleware)
require_relative "adapter/net_http_persistent"
require_relative "net_http_persistent/version" Then these all work for me: gem "faraday", "~> 1.0"
gem "faraday-net_http_persistent", path: "../Code/lostisland/faraday-net_http_persistent/" ✅ OK gem "faraday-net_http_persistent", path: "../Code/lostisland/faraday-net_http_persistent/"
gem "faraday", "~> 1.0" ✅ OK gem "faraday", "~> 2.0"
gem "faraday-net_http_persistent", path: "../Code/lostisland/faraday-net_http_persistent/" ✅ OK gem "faraday-net_http_persistent", path: "../Code/lostisland/faraday-net_http_persistent/"
gem "faraday", "~> 2.0" ✅ OK |
I was going crazy because this was working for me as well and I couldn't understand why. #!/usr/bin/env ruby
# frozen_string_literal: true
$VERBOSE = true # enable warnings
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem "faraday-net_http_persistent", path: "../../lostisland/faraday-net_http_persistent/"
gem "faraday", '~> 1.9.0' # this issue is only with 1.9.0 or prior, as 1.9.1 fixes adapter gems versions to ~> 1.0
end
require 'irb'
IRB.start(__FILE__) |
Though at this point, if we're just talking about a warning, then maybe a major release is not worth it? |
* Explicitly depend on Faraday 2.5+ (Fixes #13) * Remove unnecessary `Net::HTTP::Persistent#new` if based on arguments (we now depend on net_http_persistent ~> 4.0) * Remove unnecessary proxy patch (fixed in drbrain/net-http-persistent#59) * Use the new streaming API
* Explicitly depend on Faraday 2.5+ (Fixes #13) * Remove unnecessary `Net::HTTP::Persistent#new` if based on arguments (we now depend on net_http_persistent ~> 4.0) * Remove unnecessary proxy patch (fixed in drbrain/net-http-persistent#59) * Use the new streaming API
* Explicitly depend on Faraday 2.5+ (Fixes #13) * Remove unnecessary `Net::HTTP::Persistent#new` if based on arguments (we now depend on net_http_persistent ~> 4.0) * Remove unnecessary proxy patch (fixed in drbrain/net-http-persistent#59) * Use the new streaming API
@mattbrictson @olbrich this PR should fix this, any chance you could give it a try and let me know if it works for your specific bundle? Remember you can remove |
* Explicitly depend on Faraday 2.5+ (Fixes #13) * Remove unnecessary `Net::HTTP::Persistent#new` if based on arguments (we now depend on net_http_persistent ~> 4.0) * Remove unnecessary proxy patch (fixed in drbrain/net-http-persistent#59) * Use the new streaming API
See lostisland/faraday-net_http#25
It is necessary to include this adapter in your gemfile after Faraday or whatever else depends on Faraday or you will get errors when trying to load your app. Declaring this dependency should fix that.
The text was updated successfully, but these errors were encountered: