[BUG] HTTParty logger overrides Rails logger.
Rails 7.0.3 HTTParty 0.20.0
This bug can be reproduced by creating a simple rails application with the following model implementation.
class DummyModel < ApplicationRecord
include HTTParty
enum status: {ok: 0, not_ok: 1}
end
The above mentioned code will give the following error :
wrong number of arguments (given 0, expected 1..3)
And in the rails source code, in the file lib/active_record/enum.rb:, the logger is being overridden by HTTParty's logger.
def detect_negative_enum_conditions!(method_names)
return unless logger # problematic code, temp solution is to replace logger with ActiveRecord::Base.logger
method_names.select { |m| m.start_with?("not_") }.each do |potential_not|
inverted_form = potential_not.sub("not_", "")
if method_names.include?(inverted_form)
logger.warn "Enum element '#{potential_not}' in #{self.name} uses the prefix 'not_'." \
" This has caused a conflict with auto generated negative scopes." \
" Avoid using enum elements starting with 'not' where the positive form is also an element."
end
end
end
It looks like the HTTParty's logger function defined in lib/httparty.rb:77 is overriding the rails logger.
There would probably be other conflicts besides the occlusion of the logger when trying to include HTTParty in an ActiveRecord model. I got issues with enum methods, for example, when testing this.
Since nothing in the docs indicates that the library integrates with ActiveRecord maybe this can be closed as ~wontfix @jnunemaker?
@kabirpathak Depending on how complex your use case is, you could make HTTP calls within a Rails model by simply calling HTTParty.get,, HTTParty.post etc or to building a separate client class that includes HTTParty and doesn't inherit from ActiveRecord.
@JonMidhir Issue was resolved using the solution suggested here: https://github.com/jnunemaker/httparty/discussions/740#discussioncomment-2951273. Thanks for your reply, nonetheless.