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

Ticket #5988 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Model load fails on first load, works on second in script/console

Reported by: chris@octopod.info Assigned to: ulysses
Priority: normal Milestone:
Component: ActiveSupport Version: edge
Severity: normal Keywords: dependencies
Cc: chris@octopod.info

Description

I'm getting the

LoadError: Expected script/../config/../config/../app/models/search_term.rb to define SearchTerm error

However, instead of it being on reloading it's on the first load. This looks similar to the plugins bug #5852, but the file it's messing up on is a normal model file. This file is required by a plugin, which might have something to do with it. I've tested this out in the console, and the wierd thing is repeating the u = User.new straight after the one that causes the above works. It looks like it's reporting it can't find the class even though it has.

I've put a detailed trace that uses Dependencies.log_activity on http://pastie.caboo.se/10940/

This all works in r4727, fails in r4883

Attachments

const-missing-on-kernel.diff (1.2 kB) - added by Ulysses on 09/05/06 20:43:42.
A potential fix; awaiting discussion

Change History

08/31/06 11:55:55 changed by ulysses

Hey, thanks for the ticket. I ran into this last night as well; it's on my list.

(Who wrote this piece of crap reloading stuff anyways?)

09/05/06 20:34:04 changed by ulysses

The problem here is that the constant is being loaded into Kernel; not sure why, and perhaps we should change this to always load it into Object. See the logs:

Dependencies: called load_missing_constant(Kernel, :SearchTerm)

And: irb(main):001:0> class A; end irb(main):002:0> Kernel.const_defined? :A => false irb(main):003:0> Object.const_defined? :A => true

09/05/06 20:43:42 changed by Ulysses

  • attachment const-missing-on-kernel.diff added.

A potential fix; awaiting discussion

09/05/06 21:42:44 changed by anonymous

This fixes my original problem, but I'm still getting an issue where something that was working before isn't working now.

I use mod_secdownload with lightty, and have the following line (taken from the docs) to generate the download token.

    token = MD5::md5(secret + relative_file_path + timestamp).to_s    # Token Creation

This is fine in r4727, however I got the following error on r5016 + this patch

     NameError: uninitialized constant ProtectedAssetsController::MD5

I fixed this with:

  # in environment.rb
  require 'digest/md5'

  # in the model that was giving the problem, change the line to 
  token = Digest::MD5.new(secret + relative_file_path + timestamp).to_s    # Token Creation

Which seems better anyway, I guess rails was finding MD5 for me before.

I had one other failing test with edge + patch which seems like it's something else in rails but I'll mention it here just in case. Let me know if you want to put it in another ticket:

I had

    assert assigns(:foo).bar, assigns(:foo).errors.to_yaml

And got:

   TypeError: wrong argument type nil (expected Data)
    /usr/local/lib/ruby/1.8/yaml.rb:387:in `emit'
    /usr/local/lib/ruby/1.8/yaml.rb:387:in `quick_emit'
    /usr/local/lib/ruby/1.8/yaml/rubytypes.rb:15:in `to_yaml'
    ./test/functional/events_controller_test.rb:92:in `test_show'

When I changed it to:

   assigns(:foo).errors.full_messages

Everything was good.

09/05/06 22:36:29 changed by ulysses

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

(In [5023]) Equate Kernel.const_missing with Object.const_missing. Fixes #5988.

09/05/06 22:37:16 changed by anonymous

anonymous: (still octopod?)

Failing to load MD5 is entirely intentional; there will be some breakage surrounding this, but I rationalize it by explaining that the prior behavior was broken. (And it was.) The idea is that from now on, everyone must require their stdlibs by hand.

Closing because it sounds like this is fixed. Reopen if I misinterpreted...

09/05/06 22:44:15 changed by chris@octopod.info

Yes, it was me. It's not working for someone else with namespaced models though. I guessed the MD5 thing was intential and is fine by me :)