Forum: Ruby on Rails issue with the object cache

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
102c8cfc6464c2ed20646056414c5999?d=identicon&s=25 luis (Guest)
on 2009-03-05 10:32
(Received via mailing list)
Hi,

I am getting a method_missing error when I run my application in the
production environment unless I set config.cache_classes = false in
config/environments/production.rb. This happens in Rails 2.2.2 but not
in Rails 2.1.0. The method that is missing is one I used to have
before I edited by hand the migration that creates the table
associated with the object (I know you are discouraged to do this, but
I had started with a very simple model and thought it would be cleaner
to have the bulk of the data defined in the first migration). I wonder
if this has anything to do with the issue.

To be more specific, I changed this

  def self.up
    create_table :clients do |t|
      t.string :name, :null=>false
      t.text :office_address
      t.text :home_address

      t.timestamps
    end
    add_index(:clients, :name, :unique=>true)
  end

into

  def self.up
    create_table :clients do |t|
      t.string :last_name, :null=>false
      t.string :first_name, :null=>false
      t.text :office_address
      t.text :home_address
      <bunch of other fields>

      t.timestamps
    end
    add_index(:clients, :last_name, :unique=>true)
  end

I then ran "rake db:migrate VERSION=0" and then "rake db:migrate"

All worked fine in both development and production environments in
Rails 2.1.0, but broke in Rails 2.2.2/production with the message
"undefined method `name' for #<Client:0xb72d361c>"

From what I can tell, with the object cache enabled, Rails thinks that
the Client object still has a method called name (which it used to
have). I wonder how persistent is the object cache (I'd imagine not
across server restarts) or if the source of this problem is elsewhere.

Any help will be appreciated,

Luis
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-05 10:33
(Received via mailing list)
On Mar 5, 4:24 am, luis <luistav...@yahoo.com> wrote:

>
> All worked fine in both development and production environments in
> Rails 2.1.0, but broke in Rails 2.2.2/production with the message
> "undefined method `name' for #<Client:0xb72d361c>"

When does this error occur - what's the stack trace ?

Fred
102c8cfc6464c2ed20646056414c5999?d=identicon&s=25 luis (Guest)
on 2009-03-05 15:38
(Received via mailing list)
This happens when trying to save the Client object, here is the stack
trace

/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/attribute_methods.rb:260:in
`method_missing'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/validations.rb:398:in `send'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/validations.rb:398:in
`validates_each'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/validations.rb:397:in `each'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/validations.rb:397:in
`validates_each'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:182:in `call'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:182:in
`evaluate_method'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:166:in `call'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `run'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `each'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `send'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:90:in `run'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activesupport-2.2.2/lib/active_support/callbacks.rb:277:in
`run_callbacks'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/validations.rb:1029:in
`valid_without_callbacks?'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/callbacks.rb:286:in `valid?'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/validations.rb:1008:in
`save_without_dirty'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/dirty.rb:79:in
`save_without_transactions'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/transactions.rb:179:in `send'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/transactions.rb:179:in
`with_transaction_returning_status'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/connection_adapters/
postgresql_adapter.rb:550:in `transaction'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/transactions.rb:129:in
`transaction'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/transactions.rb:138:in
`transaction'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/transactions.rb:178:in
`with_transaction_returning_status'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/transactions.rb:146:in `save'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/transactions.rb:158:in
`rollback_active_record_state!'
/usr/local/encap/ruby-1.8.7-p72/lib/ruby/gems/1.8/gems/
activerecord-2.2.2/lib/active_record/transactions.rb:146:in `save'
app/models/client.rb:12:in `save'
app/controllers/clients_controller.rb:14:in `create'

On Mar 5, 3:33 am, Frederick Cheung <frederick.che...@gmail.com>
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-05 16:01
(Received via mailing list)
On 5 Mar 2009, at 14:37, luis wrote:

>
> This happens when trying to save the Client object, here is the stack
> trace

Looks like you still have a validation against name.

Fred
102c8cfc6464c2ed20646056414c5999?d=identicon&s=25 luis (Guest)
on 2009-03-05 16:59
(Received via mailing list)
On Mar 5, 9:00 am, Frederick Cheung <frederick.che...@gmail.com>
wrote:
>
That seems to be the case, but why? Why does it happen only with
cache_classes = true? It seems to me that the cache is not being
flushed...

thanks,

Luis
2a31ce1f0273b12896b4049bf3eb4ce8?d=identicon&s=25 Shiv N Gautam (Guest)
on 2009-03-05 17:03
(Received via mailing list)
On Thu, Mar 5, 2009 at 9:28 PM, luis <luistavera@yahoo.com> wrote:

> > > trace
> >
> > Looks like you still have a validation against name.
> >
> > Fred
> >
>
> That seems to be the case, but why? Why does it happen only with
> cache_classes = true? It seems to me that the cache is not being
> flushed...
>


The problem could be that rails caches the model schema when the server
starts.
Try to do a Model.reset_column_information where Model is the name of
your
model.

--
Shiv


>
>


--

Dick Cavett  - "If your parents never had children, chances are...
neither
will you."
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-03-05 17:41
(Received via mailing list)
On 5 Mar 2009, at 15:58, luis wrote:

>>> stack
>>> trace
>>
>> Looks like you still have a validation against name.
>>
>> Fred
>>
>
> That seems to be the case, but why? Why does it happen only with
> cache_classes = true? It seems to me that the cache is not being
> flushed...

Without seeing any code it's hard to say. One extra thing that happens
in 2.2 when cache_classes is true is that models are loaded when the
server starts up (previously they were loaded on demand). This can
mean that faulty code that was never loaded before is now loaded.

Fred
102c8cfc6464c2ed20646056414c5999?d=identicon&s=25 luis (Guest)
on 2009-03-05 19:50
(Received via mailing list)
Well, it turns out that I had left in app/models a renamed version of
the previous Client model file (client--previous.rb) which was
throwing things off. After I removed the file all worked as expected.

Thanks all for your help, and sorry for the red herring.

Luis
This topic is locked and can not be replied to.