-
Notifications
You must be signed in to change notification settings - Fork 21
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
Deprecation warning about ::UploadIO constant when used without faraday-multipart gem #36
Comments
Right, the code in there is actually using the def rewind_files(body)
return unless defined?(UploadIO)
return unless body.is_a?(Hash)
body.each do |_, value|
value.rewind if value.is_a?(UploadIO)
end
end EDIT: I filed lostisland/faraday-multipart#12 which is about getting around this deprecation warning by releasing a new major version of faraday-multipart which does not refer to old aliases. |
I remember there was a fix in This gem does not directly depend on I believe the fix here would be to replace The side-effect of this change though it that the rewind will only work if you also have the @olleolleolle what do you think? |
@iMacTia Yes, following that assumption is good. To make things slow, long and predictable, we may want to do it in a few phases.
|
That looks like a sound plan, and will definitely avoid surprises for anyone who is somehow relying on UploadIO payload without the |
I don't think that the Since the Something like this: def upload_io_const
@upload_io_const ||= if defined?(::Multipart::Post::UploadIO)
::Multipart::Post::UploadIO
elsif defined?(::UploadIO)
::UploadIO
end
end
def rewind_files(body)
return unless upload_io_const
return unless body.is_a?(Hash)
body.each_value do |value|
value.rewind if value.is_a?(upload_io_const)
end
end Alternatively, the implementation from |
Yeah so I was trying to avoid replicating the same logic in Basically if you want |
OK so I've just tried the following and was able to confirm that using require 'faraday'
require 'multipart/post'
file = UploadIO.new(File.new('./.gitignore'), 'text', '.gitignore')
conn = Faraday.new('https://httpbingo.org')
conn.post('/anything/echo', { file: file }) which returns the following response body {
"args": {},
"headers": { ... },
"method": "POST",
"url": "https://httpbingo.org/anything/echo",
"data": "file=%23%3CMultipart%3A%3APost%3A%3AUploadIO%3A0x000000011c694ed0%3E",
"files": {},
"form": {
"file": [
"#<Multipart::Post::UploadIO:0x000000011c694ed0>"
]
},
"json": null
} Based on this, I don't think we need the gradual changes or backwards compatibility that was suggested in this comment, and instead we can just change the code to check for @jimeh @olleolleolle am I missing anything? |
@iMacTia Yep, that all makes sense to me :) No point in trying to be compatible with just the |
Nice, nice! |
Basic Version Info
Faraday Version: 2.8.1
Ruby Version: 3.2.2
Issue description
If your project has the
multipart-post
gem loaded, and usesfaraday-retry
for POST requests without thefaraday-multipart
gem, theFaraday::Retry::Middleware#rewind_files
method triggers a deprecation warning:We specifically noticed this via the
acme-client
gem, which performs post requests with retries enabled.Most people may not notice this however, as it requires you to set
Warning[:deprecated] = true
for Ruby to emit these deprecation warnings. We've only discovered due to our Ruby 2 -> 3 and Rails 6 -> 7 upgrades, as we've enabled notifications for all deprecation warnings during this process.Actual behavior
This is because the Middleware class is referring to the
Faraday::UploadIO
constant from thefaraday-multipart
gem. If that gem is not part of the dependency tree however, it will instead treat it as::UploadIO
, which is marked as a deprecated constant here in themultipart-post
gem.Expected behavior
No deprecation warning is triggered.
Also,
faraday-retry
probably should not rely on / expect a constant from another gem (faraday-multipart
) which it does not depend upon.Steps to reproduce
The text was updated successfully, but these errors were encountered: