Skip to content
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

Fix MySqlAdapter superclass bug via class_eval loading of superclasses #209

Merged
merged 1 commit into from
May 15, 2013

Conversation

tommeier
Copy link
Contributor

To get it working with my current setup (a lot of gem dependencies) and Rails 3.2.13.

Removing the superclass mismatch for class MysqlAdapter by class_eval as opposed to monkey patching the superclass.

It was still erroring for me with the fix in #185. Would be great if @etagwerker (or others where this is an issue) could check if this fix also works for them.

@tommeier tommeier mentioned this pull request May 15, 2013
@tommeier
Copy link
Contributor Author

FYI: You'll need to regenerate the .gemspec with current merged master I get this warning on bundle install

database_cleaner at /opt/boxen/rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/bundler/gems/database_cleaner-9bf038d5c287 did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
  ["History.txt"] are not files

(History.txt should be History.rdoc)

bmabey added a commit that referenced this pull request May 15, 2013
Fix MySqlAdapter superclass bug via class_eval loading of superclasses
@bmabey bmabey merged commit 6a3d236 into DatabaseCleaner:master May 15, 2013
@bmabey
Copy link
Contributor

bmabey commented May 15, 2013

Thanks, I've merged this in and fixed the gemspec problem you pointed out.

@etagwerker, would you mind pointing your Gemfile to git://github.com/bmabey/database_cleaner.git master branch to see if this fix resolves the issue for you?

@etagwerker
Copy link
Member

@bmabey I wish I could say it all works alright pointing to master, but it doesn't.

I get this stack trace if I try:

undefined local variable or method `postgresql_version' for #<ActiveRecord::ConnectionAdapters::Mysql2Adapter:0x007fe5aafab0d0> (NameError)
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/bundler/gems/database_cleaner-7effdb71cbab/lib/database_cleaner/active_record/truncation.rb:123:in `db_version'
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/bundler/gems/database_cleaner-7effdb71cbab/lib/database_cleaner/active_record/truncation.rb:131:in `restart_identity'
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/bundler/gems/database_cleaner-7effdb71cbab/lib/database_cleaner/active_record/truncation.rb:140:in `truncate_tables'
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/bundler/gems/database_cleaner-7effdb71cbab/lib/database_cleaner/active_record/truncation.rb:234:in `block in clean'
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/gems/mysql2-0.2.18/lib/active_record/connection_adapters/mysql2_adapter.rb:186:in `disable_referential_integrity'
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/bundler/gems/database_cleaner-7effdb71cbab/lib/database_cleaner/active_record/truncation.rb:230:in `clean'
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/bundler/gems/database_cleaner-7effdb71cbab/lib/database_cleaner/base.rb:87:in `clean'
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/bundler/gems/database_cleaner-7effdb71cbab/lib/database_cleaner/configuration.rb:79:in `block in clean'
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/bundler/gems/database_cleaner-7effdb71cbab/lib/database_cleaner/configuration.rb:79:in `each'
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/bundler/gems/database_cleaner-7effdb71cbab/lib/database_cleaner/configuration.rb:79:in `clean'
      /Users/etagwerker/.rvm/gems/ruby-1.9.3-p327@ombu/gems/cucumber-rails-1.3.1/lib/cucumber/rails/hooks/database_cleaner.rb:9:in `After'

There is obviously some mixup, as it's looking for postgres info in a Mysql2Adapter.

My application uses Redis, MySQL and Postgres (from a Rails engine)

In that test, I am not testing the Rails engine, just my application.

Any ideas?

@simi
Copy link

simi commented Jun 10, 2013

@bmabey Not fixed at all. Try to run test for https://github.com/svenfuchs/globalize3/tree/rails4 (rails4 branch).

123) Error:
LogMissingTranslationsTest#test_logs_the_missing_translation_to_I18n.missing_translations_logger:
NameError: undefined local variable or method `postgresql_version' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x000000034da4b0>
    /home/retro/.rvm/gems/ruby-1.9.3-p374/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/active_record/truncation.rb:123:in `db_version'
    /home/retro/.rvm/gems/ruby-1.9.3-p374/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/active_record/truncation.rb:131:in `restart_identity'
    /home/retro/.rvm/gems/ruby-1.9.3-p374/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/active_record/truncation.rb:140:in `truncate_tables'
    /home/retro/.rvm/gems/ruby-1.9.3-p374/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/active_record/truncation.rb:234:in `block in clean'
    /home/retro/.rvm/gems/ruby-1.9.3-p374/bundler/gems/rails-ebf2113a0565/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:307:in `disable_referential_int
egrity'
    /home/retro/.rvm/gems/ruby-1.9.3-p374/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/active_record/truncation.rb:230:in `clean'
    /home/retro/.rvm/gems/ruby-1.9.3-p374/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/base.rb:86:in `clean'
    /home/retro/.rvm/gems/ruby-1.9.3-p374/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/configuration.rb:79:in `block in clean'
    /home/retro/.rvm/gems/ruby-1.9.3-p374/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/configuration.rb:79:in `each'
    /home/retro/.rvm/gems/ruby-1.9.3-p374/bundler/gems/database_cleaner-5dc784af6661/lib/database_cleaner/configuration.rb:79:in `clean'
    /home/retro/work/fun/globalize3/test/test_helper.rb:34:in `teardown'

Switch to DatabaseCleaner.strategy = :transaction is solution for now.

@tommeier
Copy link
Contributor Author

Yup this is because of the superclass overwrite. We can fix this quickly by adding the postgres subclass monkey patch again, but the real fix is the proper decoration of the connection adapters. I started but I'm not familiar with the ARJDBC workaround decisions.

@simi
Copy link

simi commented Jun 11, 2013

@tommeier can you provide fast hack fix (maybe only in some branch)? I can help with proper fix, but I don't know database_cleaner codebase well. I spent yesterday one hour looking into it. This bug is triggered in features, not in specs.

@tommeier
Copy link
Contributor Author

Hi @simi, there seems to be a lot of edge cases in this truncation.rb file. I doubt I'll find them all.

Could you please try with:

gem 'database_cleaner', git: 'https://github.com/tommeier/database_cleaner', ' branch: 'fix-superclass'

@tomash
Copy link

tomash commented Jul 2, 2013

Confirmed that @tommeier 's fork in fix-superclass fixes the undefined method postgresql_version in globalize3. @simi , globalize's rails4 branch is now down to just 13 failures :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants