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

Ticket #6039 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Dependencies.clear() mishandles constants defined in namespaces.

Reported by: nathan@otherward.net Assigned to: ulysses
Priority: normal Milestone: 1.x
Component: ActiveSupport Version: edge
Severity: normal Keywords:
Cc:

Description

A project I am working on uses a model named Process. This would normally override the ::Process module, but I've wrapped it in a namespace for this application to prevent that: /app/models/flex_data/process.rb defines FlexData::Process

script/console log demonstrating the problem:

$ script/console
Loading development environment.
>> Dependencies.clear
=> nil
>> Object.const_defined? :Process
=> true
>> Object.const_defined? :FlexData
=> false
>> FlexData::Process
=> FlexData::Process
>> Object.const_defined? :FlexData
=> true
>> FlexData.const_defined? :Process
=> true
>> FlexData.const_get(:Process).class
=> Class
>> Object.const_get(:Process).class 
=> Module
>> Dependencies.clear
=> nil
>> Object.const_defined? :Process
=> false

The relevant log entry for the second clear() call (Dependencies.log_activity = true):

Dependencies: called clear()
Dependencies: removing constant FlexData
Dependencies: removing constant Process

More to the point, this causes problems with any controller that uses FlexData::Process (or anything else that would collide with the base global namespace.) The first load is successful, but the second fails with a LoadError. I have pasted the full log at http://pastie.caboo.se/11915 In particular see the logging .diff I'm using for additional debug information in Dependencies.load_missing_constant (attached)

The first request:
Dependencies: loading script/../config/../app/models/flex_data/process.rb defined Process, FlexData::Process
Dependencies: FlexData tried to load Process (FlexData::Process) from script/../config/../app/models/flex_data/process.rb: true

The second request:
Dependencies: loading script/../config/../app/models/flex_data/process.rb defined FlexData::Process
Dependencies: Object tried to load Process (Process) from script/../config/../app/models/flex_data/process.rb: false
LoadError (Expected script/../config/../app/models/flex_data/process.rb to define Process):
.//vendor/rails/activesupport/lib/active_support/dependencies.rb:236:in `load_missing_constant'

Attachments

load_missing_constant_debug.diff (0.8 kB) - added by nathan@otherward.net on 09/05/06 23:28:33.
patch to dependencies.rb for additional load_missing_constant debug

Change History

09/05/06 23:28:33 changed by nathan@otherward.net

  • attachment load_missing_constant_debug.diff added.

patch to dependencies.rb for additional load_missing_constant debug

09/05/06 23:36:14 changed by ulysses

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

(In [5035]) Fix logic error in determining what was loaded by a given file. Closes #6039.