Debugging my Rails app gets "Mysql not loaded"

I'm a new RubyMine user ... When I try to debug the development configuration of my Rails 2.3.4 application from within RubyMine 2.0.2, the first couple of page requests might work, but quickly I start getting FAILSAFE "Status; 500 Internal Server Error" / "Mysql not loaded" tracebacks in the log. This error is being raised from gems/activerecord-2.3.4/lib/active_record/connection_adapters/mysql_adapter.rb, line 7:
    raise 'Mysql not loaded' unless defined?(::Mysql)

I *think* "Mysql" is defined by the native library part of the mysql gem (2.8.1): it becomes defined during the "require 'mysql_api'" at the top of gems/mysql-2.8.1/lib/mysql.rb (which only executes once, at app startup, not per-request).

This app runs fine in development mode outside of Rubymine (using Webrick), and fine in production.

I don't have this problem if I create a brand-new Rails 2.3.4 app (using mysql), create a scaffold, migrate, and debug -- everything works fine; I'm guessing that means there's some interaction with one of the gems the app uses.

Anyone have any suggestions on what to try next?

Ubuntu 9.10 64-bit; Ruby Enterprise Edition 2009.10, which is  1.8.7p174-based; here's RubyMine's external libraries list for the project --

actionmailer 2.3.4
actionpack 2.3.4
activerecord 2.3.4
activeresource 2.3.4
activesupport 2.3.4
ashleym1972-syslog_logger 1.6.3
authlogic 2.1.3
cancan 1.0.2
columnize 0.3.1
compass 0.10.0.pre8
compass-baseline 0.2.3
compass-colors 0.3.1
csspool 0.2.6
daemons 1.0.10
facets 2.8.1
faker 0.3.1
fiveruns_tuneup 0.8.20
formtastic 0.9.8
haml 2.2.24
hoe 2.4.0
hoptoad_notifier 2.1.2
hpricot 0.8.2
json_pure 1.2.0
libxml-ruby 1.1.3
linecache 0.43
mislav-will_paginate 2.3.11
mocha 0.9.7
mysql 2.8.1
paper_trail 1.5.0
populator 0.2.5
rack 1.0.1
rails 2.3.4
rake 0.8.7
ruby-debug 0.10.3
ruby-debug-base 0.10.3
rubyforge 2.0.3
shoulda 2.10.2
sqlite3-ruby 1.2.5

Comment actions Permalink

I realized that since the debugger works, I could probably debug this further myself, so running my app side-by-side with another instance of RubyMine debugging the generic 2.3.4 app that didn't show the problem, I figured out that my app was somehow causing the MySQL adapter to get loaded in a way that confused Rails' loading (and auto-unloading) mechanism: ::Mysql was getting undefined when ActionController's dispatcher calls cleanup_application, which calls ActiveSupport::Dependencies.clear, which calls remove_unloadable_constants!. The generic app didn't have this problem, because "Mysql" didn't get added to the autoloaded_constants list by whatever mechanism caused it to load the adapter.

I still don't know the exact reason, but my app was causing the MySQL adapter to get loaded by an initializer that was constantizing a string that was the name of one of my ActiveRecord models. This somehow took a different path than the generic app's loading of the adapter, which was happening when the first database connection was needed.

I made my problem go away by adding a call to ActiveRecord::Base.connection from a very early one of my initializers, which forced the adapter to get loaded the "right" way (without adding Mysql to the autoloaded_constants list), and all's good now.

Comment actions Permalink

Had same problem - on Win7 x64. Fixed by adding  require 'mysql' to mysql_adapter.rb.


Please sign in to leave a comment.