basecamp / marginalia

Attach comments to ActiveRecord's SQL queries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

undefined method `execute' for class `ActiveRecord::ConnectionAdapters::SQLiteAdapter' (NameError)

rilian opened this issue · comments

rails 3.0.12

/gems/marginalia-1.0.2/lib/marginalia.rb:12:in alias_method': undefined methodexecute' for class `ActiveRecord::ConnectionAdapters::SQLiteAdapter' (NameError)

we dont use SQLite in environment at all

there were no problems with marginalia-1.0.0

SQLite support was added after 1.0.0.

I can't directly reproduce on an app with the same rails version, but pushed a change that should fix it anyway. Can you test against git master? If that fixes it, I'll release 1.0.3 with the fix.

i have tested marginalia's bleeding edge version, but no success

as said on README, i have

in Gemfile:

group :development do
  gem 'marginalia', :git => 'https://github.com/37signals/marginalia.git'
end

in initializers/marginalia.rb

if Rails.env.development?
  require 'marginalia'
  Marginalia::Railtie.insert
end

in database.yml

development:
  adapter: mysql2
  encoding: utf8
  reconnect: true
  database: projectname_dev
  pool: 5
  username: username
  password: password

and when i run rails s i get

/Users/rilian/.rvm/gems/ruby-1.9.3-p125@gemsetname/bundler/ gems/marginalia-0110a04a192f/lib/marginalia.rb:13:in `alias_method': undefined method `execute' for class `ActiveRecord::ConnectionAdapters::SQLiteAdapter' (NameError)

It shouldn't be necessary to explicitly run the insertion on Rails 3 -- it's taken care of automatically.

Still, I don't believe that's the issue here -- I've pushed a minimal example app using mysql2, rails 3.0.12, and marginalia master to https://github.com/noahhl/marginaliatestapp and can't reproduce the issue there.

Can you provide any more details about your setup (other gems, etc), or even better, push a minimal test app that reproduces the problem that I can take a look at?

i have just tested marginalia 1.0.3, with

config/initializers/marginalia.rb

require 'marginalia/railtie' if Rails.env.development?

and when i run rails s it said

/Users/rilian/.rvm/gems/ruby-1.9.3-p125@project/gems/marginalia-1.0.3 /lib/marginalia.rb:13:in `alias_method': undefined method `execute' for class `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' (NameError)

still, in the project we dont have pg nor sqlite3, only mysql2

i have checked the insert_into_active_record method with debugger and it is so:

(rdb:1) p defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
"constant"
(rdb:1) p defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
"constant"
(rdb:1) p defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
nil
(rdb:1) p defined? ActiveRecord::ConnectionAdapters::SQLiteAdapter
"constant"
(rdb:1) p ActiveRecord::ConnectionAdapters.constants
[:Column, :IndexDefinition, :ColumnDefinition, :TableDefinition, :Table, :SchemaStatements, 
:DatabaseStatements, :Quoting, :ConnectionPool, :ConnectionHandler, 
:ConnectionManagement, :QueryCache, :DatabaseLimits, :AbstractAdapter,
 :SQLiteAdapter, :OracleAdapter, :PostgreSQLAdapter, :Mysql2IndexDefinition,
 :Mysql2Column, :Mysql2Adapter]

hope this helps

1.03 works if i comment out all the checks except mysql2

    def self.insert_into_active_record
      if defined? ActiveRecord::ConnectionAdapters::Mysql2Adapter
        ActiveRecord::ConnectionAdapters::Mysql2Adapter.module_eval do
          include Marginalia::ActiveRecordInstrumentation
        end
      end

      #if defined? ActiveRecord::ConnectionAdapters::MysqlAdapter
      #  ActiveRecord::ConnectionAdapters::MysqlAdapter.module_eval do
      #    include Marginalia::ActiveRecordInstrumentation
      #  end
      #end
      #
      #if defined? ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
      #  ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.module_eval do
      #    include Marginalia::ActiveRecordInstrumentation
      #  end
      #end
      #
      #if defined? ActiveRecord::ConnectionAdapters::SQLiteAdapter
      #  ActiveRecord::ConnectionAdapters::SQLiteAdapter.module_eval do
      #    include Marginalia::ActiveRecordInstrumentation
      #  end
      #end

    end

looks i found a solution, i'll send a pull request

Merged your pull request.

Out of curiosity, do you have any third party gems that might be loading all of these unused AR::ConnectionAdapters? On none of the 5 apps I just checked ranging from 2.3 to rails master are any connection adapters other than the actual used one loaded.

well i have checked Gemfile.lock and any of these depends on SQLite or PG ...

Gemfile

source 'http://rubygems.org'

gem "rake", "0.9.2.2"
gem 'rails', '3.0.12'
gem 'jquery-rails', '>= 0.2.6'

gem 'mysql2', :git => 'https://github.com/brianmario/mysql2.git', :branch => "0.2.x"
#gem 'mysql2', '0.2.18'

gem "cgi_multipart_eof_fix"
gem "fastthread"

gem 'devise'
gem 'devise_security_extension'
gem 'devise_oauth2_providable' # 0.3.8 as 1.x.x needs rails 3.1
gem 'cancan', '>= 1.5'

gem 'meta_search'
gem 'meta_where'

gem "will_paginate"
gem 'paperclip', '2.3.16'

gem 'nested_set'
gem 'workflow'

gem 'populator'

gem 'kramdown' # for markdown format

gem 'delayed_paperclip', '0.6.5'

gem 'resque', :require => 'resque/server'
gem 'resque-retry', '>= 1.0.0.a' # needs testing
gem 'amqp'
gem 'daemons'

gem 'whenever', :require => false

gem 'showoff-io'
gem 'exceptional'
gem 'has_scope'
gem 'wicked_pdf'

gem 'json_builder'
gem 'hashie'

group :development do
  gem 'marginalia'
end

group :development, :test do
  gem 'debugger'
  gem 'rspec_multi_matchers'
  gem 'launchy'
  gem 'awesome_print'
  gem "factory_girl_rails"
end

group :test do
  gem 'rails_code_qa'
  gem 'capistrano-ext'
  gem 'capistrano', '2.5.19'
  gem "rvm-capistrano"
  gem 'cucumber-rails', :require => false
  gem 'capybara'
  gem "shoulda"
  gem "rspec-rails"
  gem 'autotest-standalone'
  gem 'database_cleaner'
  gem 'selenium-client'
  gem 'selenium-webdriver'
  gem "fuubar"

  gem "fakeweb"
  gem 'evented-spec'
end

group :production do
  gem 'json'
  gem 'newrelic_rpm'
  gem 'hoptoad_notifier'
  gem 'rack-ssl', :require => 'rack/ssl'
  gem 'unicorn'
end