Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9743 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

[PATCH] "already initialized constant OPTIONS" (Mongrel) when upgraded from 1.2.3 to 2.0

Reported by: grempe Assigned to: core
Priority: high Milestone:
Component: Railties Version: edge
Severity: minor Keywords:
Cc: mislav

Description

Cannot seem to run ./script/server start from upgraded rails 1.2.3 application without error.

To replicate (tested on OS X machine and linux server):

create a simple rails app using rails 1.2.3:

cd /tmp/rails
rails foo

[generates rails 1.2.3 app]

Run ./script/server start

[MONGREL SERVER STARTS OK]

Now upgrade foo app to Rails 2.0 PR:

rake rails:freeze:edge TAG=rel_2-0-0_PR

Try to start server again now that upgrade is complete and local app is frozen to Rails 2.0 PR:

[glenn@mac-mini foo]$ ./script/server 
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
Exiting
/private/tmp/rails/foo/vendor/rails/railties/lib/commands/servers/mongrel.rb:16: warning: already initialized constant OPTIONS
/private/tmp/rails/foo/vendor/rails/railties/lib/commands/servers/mongrel.rb:19: undefined method `options' for []:Array (NoMethodError)
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `gem_original_require'
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in `require'
        from /private/tmp/rails/foo/vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require'
        from /private/tmp/rails/foo/vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'
        from /private/tmp/rails/foo/vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require'
        from /private/tmp/rails/foo/vendor/rails/railties/lib/commands/server.rb:39
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
        from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
        from ./script/server:3
[glenn@mac-mini foo]$ 


Attachments

require-frameworks.diff (3.2 kB) - added by mislav on 10/03/07 22:12:14.

Change History

10/01/07 04:12:15 changed by rmm5t

grempe, I know this sounds like a kludge of a workaround, but try freezing to the preview release twice. For example:

$ rails foo
#=> Creates a rails 1.2.3 project

$ rake rails:freeze:edge TAG=rel_2-0-0_PR
#=> I haven't fully investigated what goes wrong here, 
#=> but it doesn't seem to put the correct files in place.

$ rake rails:freeze:edge TAG=rel_2-0-0_PR
#=> Fixes the file placement problem.

$ ./script/server
#=> Should work now.

10/01/07 07:23:42 changed by grempe

OK, that is a strange one... Is this a known issue with rake rails:freeze:edge?

So I ran it a second time within my Git repository. TO help with your investigation below is the diff with the second run vs. what was in place and commited on my branch after the first run of freeze.

It does consistently seem to require running rake rails:freeze:edge at least twice in order to run the server process cleanly. And clearly this is not just related to the server process. Large chunks of rails are apparently not being installed if you do rake rails:freeze:edge only once!

Thanks for the pointer. This bug should remain open though until this freeze issue is resolved. The instructions that DHH gave in the PR2 announcement tonight will not work for many people if this is a common error case. I suspect lots of folks may get bitten by this.

Thanks,

Glenn

SECOND RUN OF FREEZE DIFF

[glenn@mac-mini elastic (rails_rel_2-0-0_PR)]$ git st
# On branch rails_rel_2-0-0_PR
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       new file:   elastic/vendor/rails/activeresource/CHANGELOG
#       new file:   elastic/vendor/rails/activeresource/MIT-LICENSE
#       new file:   elastic/vendor/rails/activeresource/README
#       new file:   elastic/vendor/rails/activeresource/Rakefile
#       new file:   elastic/vendor/rails/activeresource/lib/active_resource.rb
#       new file:   elastic/vendor/rails/activeresource/lib/active_resource/base.rb
#       new file:   elastic/vendor/rails/activeresource/lib/active_resource/connection.rb
#       new file:   elastic/vendor/rails/activeresource/lib/active_resource/custom_methods.rb
#       new file:   elastic/vendor/rails/activeresource/lib/active_resource/formats.rb
#       new file:   elastic/vendor/rails/activeresource/lib/active_resource/formats/json_format.rb
#       new file:   elastic/vendor/rails/activeresource/lib/active_resource/formats/xml_format.rb
#       new file:   elastic/vendor/rails/activeresource/lib/active_resource/http_mock.rb
#       new file:   elastic/vendor/rails/activeresource/lib/active_resource/validations.rb
#       new file:   elastic/vendor/rails/activeresource/lib/active_resource/version.rb
#       new file:   elastic/vendor/rails/activeresource/lib/activeresource.rb
#       new file:   elastic/vendor/rails/activeresource/test/abstract_unit.rb
#       new file:   elastic/vendor/rails/activeresource/test/authorization_test.rb
#       new file:   elastic/vendor/rails/activeresource/test/base/custom_methods_test.rb
#       new file:   elastic/vendor/rails/activeresource/test/base/equality_test.rb
#       new file:   elastic/vendor/rails/activeresource/test/base/load_test.rb
#       new file:   elastic/vendor/rails/activeresource/test/base_errors_test.rb
#       new file:   elastic/vendor/rails/activeresource/test/base_test.rb
#       new file:   elastic/vendor/rails/activeresource/test/connection_test.rb
#       new file:   elastic/vendor/rails/activeresource/test/fixtures/beast.rb
#       new file:   elastic/vendor/rails/activeresource/test/fixtures/person.rb
#       new file:   elastic/vendor/rails/activeresource/test/fixtures/street_address.rb
#       new file:   elastic/vendor/rails/activeresource/test/format_test.rb
#       new file:   elastic/vendor/rails/activeresource/test/setter_trap.rb
#
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#
#       deleted:    elastic/vendor/rails/actionwebservice/CHANGELOG
#       deleted:    elastic/vendor/rails/actionwebservice/MIT-LICENSE
#       deleted:    elastic/vendor/rails/actionwebservice/README
#       deleted:    elastic/vendor/rails/actionwebservice/Rakefile
#       deleted:    elastic/vendor/rails/actionwebservice/TODO
#       deleted:    elastic/vendor/rails/actionwebservice/examples/googlesearch/README
#       deleted:    elastic/vendor/rails/actionwebservice/examples/googlesearch/autoloading/google_search_api.rb
#       deleted:    elastic/vendor/rails/actionwebservice/examples/googlesearch/autoloading/google_search_controller.rb
#       deleted:    elastic/vendor/rails/actionwebservice/examples/googlesearch/delegated/google_search_service.rb
#       deleted:    elastic/vendor/rails/actionwebservice/examples/googlesearch/delegated/search_controller.rb
#       deleted:    elastic/vendor/rails/actionwebservice/examples/googlesearch/direct/google_search_api.rb
#       deleted:    elastic/vendor/rails/actionwebservice/examples/googlesearch/direct/search_controller.rb
#       deleted:    elastic/vendor/rails/actionwebservice/examples/metaWeblog/README
#       deleted:    elastic/vendor/rails/actionwebservice/examples/metaWeblog/apis/blogger_api.rb
#       deleted:    elastic/vendor/rails/actionwebservice/examples/metaWeblog/apis/blogger_service.rb
#       deleted:    elastic/vendor/rails/actionwebservice/examples/metaWeblog/apis/meta_weblog_api.rb
#       deleted:    elastic/vendor/rails/actionwebservice/examples/metaWeblog/apis/meta_weblog_service.rb
#       deleted:    elastic/vendor/rails/actionwebservice/examples/metaWeblog/controllers/xmlrpc_controller.rb
#       deleted:    elastic/vendor/rails/actionwebservice/install.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/api.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/base.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/casting.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/client.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/client/base.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/client/soap_client.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/client/xmlrpc_client.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/container.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/container/action_controller_container.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/container/delegated_container.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/container/direct_container.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/dispatcher.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/dispatcher/abstract.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/dispatcher/action_controller_dispatcher.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/invocation.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/protocol.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/protocol/abstract.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/protocol/discovery.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/protocol/soap_protocol.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/protocol/soap_protocol/marshaler.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/protocol/xmlrpc_protocol.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/scaffolding.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/struct.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/support/class_inheritable_options.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/support/signature_types.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/templates/scaffolds/layout.erb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/templates/scaffolds/layout.rhtml
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/templates/scaffolds/methods.erb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/templates/scaffolds/methods.rhtml
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/templates/scaffolds/parameters.erb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/templates/scaffolds/parameters.rhtml
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/templates/scaffolds/result.erb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/templates/scaffolds/result.rhtml
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/test_invoke.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/action_web_service/version.rb
#       deleted:    elastic/vendor/rails/actionwebservice/lib/actionwebservice.rb
#       deleted:    elastic/vendor/rails/actionwebservice/setup.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/abstract_client.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/abstract_dispatcher.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/abstract_unit.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/api_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/apis/auto_load_api.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/apis/broken_auto_load_api.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/base_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/casting_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/client_soap_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/client_xmlrpc_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/container_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/dispatcher_action_controller_soap_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/dispatcher_action_controller_xmlrpc_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/fixtures/db_definitions/mysql.sql
#       deleted:    elastic/vendor/rails/actionwebservice/test/fixtures/users.yml
#       deleted:    elastic/vendor/rails/actionwebservice/test/gencov
#       deleted:    elastic/vendor/rails/actionwebservice/test/invocation_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/run
#       deleted:    elastic/vendor/rails/actionwebservice/test/scaffolded_controller_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/struct_test.rb
#       deleted:    elastic/vendor/rails/actionwebservice/test/test_invoke_test.rb
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       elastic/pastie-99900.rb
[glenn@mac-mini elastic (rails_rel_2-0-0_PR)]$ 

10/01/07 12:50:09 changed by rmm5t

Okay, here is what I suspect to be the problem:

Running rake rails:freeze:edge for the first time looks at the Rails 1.2.3 rake tasks because that is all that's available on your machine. The 1.2.3 version of this task includes this at the end:

# From v1.2.3
for framework in %w( railties actionpack activerecord actionmailer activesupport actionwebservice )
  system "svn export #{rails_svn}/#{framework} vendor/rails/#{framework}" + (ENV['REVISION'] ? " -r #{ENV['REVISION']}" : "")
end

Because the frameworks are hard-coded, note the absence of activeresource and the inclusion of actionwebservice. This yields missing dependencies in rails because activeresource is missing and causes the server to crap out on init.

Of course, the newer version of rails:freeze:edge contains this:

# From v2.0 PR
for framework in %w(railties actionpack activerecord actionmailer activesupport activeresource)
  system "svn export #{rails_svn}/#{framework} vendor/rails/#{framework}" + (ENV['REVISION'] ? " -r #{ENV['REVISION']}" : "")
end

So, because the new version is now available, the second run of this task properly constructs the contents vendor/rails.

This is really difficult (near impossible) problem to solve, because it requires changing code in the existing, published version of Rails 1.2.3. I think the best thing to do is to just document this and recommend trying Rails2 in other ways (freezing manually, using the PR gem, or using the workaround described here).

Long term, rails:freeze:edge should probably be modified to just pull all frameworks under the rails repository directory, but this first requires that unused frameworks like actionwebservice be moved out of the core location.

10/03/07 22:12:14 changed by mislav

  • attachment require-frameworks.diff added.

10/03/07 22:19:20 changed by mislav

  • cc set to mislav.
  • keywords deleted.
  • severity changed from major to minor.
  • summary changed from Rails 2.0 PR - Problem starting mongrel server in upgraded 1.2.3 rails app (rel_2-0-0_PR) to [PATCH] "already initialized constant OPTIONS" (Mongrel) when upgraded from 1.2.3 to 2.0.

I've added a simple patch with tests. It does 2 things:

  1. it avoids adding load paths for frameworks it isn't going to require (not related to the issue, but a right thing to do)
  2. it re-raises a LoadError in require_frameworks so that Mongrel doesn't get the chance to swallow it.

With this patch users get a nice error: "no such file to load -- active_resource" and can immediately know what's going on.

10/04/07 02:30:36 changed by kamal

I created a patch some while back to fix the Rake task when freezing. Check out #8717

10/04/07 04:16:09 changed by nzkoz

  • status changed from new to closed.
  • resolution set to fixed.

(In [7738]) Tidy up framework initialization code to ensure that it doesn't add folders to the load path that it doesn't intend to require.

Work around mongrel swallowing LoadErrors to ensure that users get more helpful errors if active_resource is required but not missing. [mislav] Closes #9743

10/05/07 20:10:28 changed by grempe

Just following up for posterity on this now closed bug. I confirmed that running 'rake rails:freeze:edge TAG=rel_2-0-0_PR' on a sample rails app generated with v 1.2.4 (instead of 1.2.3) does indeed freeze rails PR2 cleanly and the server process starts cleanly as well with ./script/server.

I also confirmed that running 'rake rails:freeze:edge TAG=rel_2-0-0_PR' twice in that new 1.2.4 rails app does not in any way modify, add, remove any files created in the first freeze (this is different behavior than when freezing a rails 1.2.3 app).

So it seems that users should keep in mind the following rule of thumb when upgrading an existing rails app to Rails 2.0:

* If the app was generated with Rails 1.2.3 or earlier originally you will need to run 'rake rails:freeze:edge TAG=rel_2-0-0_PR' TWO times in order to get the update you intend.

* If the app was generated with Rails 1.2.4 then running 'rake rails:freeze:edge TAG=rel_2-0-0_PR' only ONE time should do the trick.

10/05/07 20:55:41 changed by mislav

Exactly. I've written about that on my blog: Rails 2.0: taking the plunge