kvokka / pp_sql

Rails ActiveRecord SQL queries log beautifier
MIT License
265 stars 9 forks source link

Error in Rails 4.2 #5

Closed michaelkeenan closed 7 years ago

michaelkeenan commented 7 years ago

It looks like this is designed for Rails 5 - maybe add that to the README under Require?

When I run it on a Rails 4.2, e.g.:

Album.where(id: 1)

It shows an error, the beginning of which is:

Could not log "sql.active_record" event. ArgumentError: wrong number of arguments (1 for 2)
["/Users/michaelkeenan/.rvm/gems/ruby-2.2.3@maenad/gems/activerecord-4.2.7/lib/active_record/log_subscriber.rb:23:in `render_bind'"
"/Users/michaelkeenan/.rvm/gems/ruby-2.2.3@maenad/gems/pp_sql-0.2.0/lib/pp_sql.rb:41:in `block in sql'"

Checking the difference between the Rails 5 version of render_bind and the Rails 4.2 version, I see that there's two arguments in Rails 4.2, and one argument in 5. So (though I haven't tested it specifically), that'll be why this is occurring.

Similarly, when I try:

Album.all

I get this error:

Could not log "sql.active_record" event. NoMethodError: undefined method `colorize_payload_name' for #<ActiveRecord::LogSubscriber:0x007fccef1f2e08>
["/Users/michaelkeenan/.rvm/gems/ruby-2.2.3@maenad/gems/pp_sql-0.2.0/lib/pp_sql.rb:44:in `sql'"

colorize_payload_name is a private method in the Rails 5 log_subscriber, but doesn't exist in 4.2.

kvokka commented 7 years ago

Thank you for so full description!

I've just made fixup for Rails 4.2, so, you may try out gem version 0.2.2

Enjoy!

redtachyons commented 7 years ago

I tried 0.2.5 and it is not compatible with rails 4.2.8, I had to monkey patch it get it working. *args hack in the code didn't worked for me

gerrywastaken commented 6 years ago

@kvokka I have a colleague who is running into this issue on rails 5.1. Any chance you remember the commit where the fix was made?

gerrywastaken commented 6 years ago

Was this it? https://github.com/kvokka/pp_sql/commit/ec93e83df34edaf0955ab392df3aca7eb3e7c06a#diff-63b8b760ae408516fb5a78b827564dcdR88