# Issue with the object cache

**URL:** <https://www.ruby-forum.com/t/issue-with-the-object-cache/162054>\
**Category:** Rails\
**Created:** [March 5, 2009, 10:32am UTC](https://www.ruby-forum.com/t/issue-with-the-object-cache/162054 "2009-03-05T10:32:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![luis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@luis](https://www.ruby-forum.com/u/luis)\
**Post date:** [March 5, 2009, 10:32am UTC](https://www.ruby-forum.com/t/issue-with-the-object-cache/162054/1 "2009-03-05T10:32:40Z")

</div>

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

```
  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

---

<div class="post-metadata">

**Author:** ![luis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@luis](https://www.ruby-forum.com/u/luis)\
**Post date:** [March 5, 2009, 10:33am UTC](https://www.ruby-forum.com/t/issue-with-the-object-cache/162054/2 "2009-03-05T10:33:52Z")

</div>

On Mar 5, 4:24 am, luis [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![luis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@luis](https://www.ruby-forum.com/u/luis)\
**Post date:** [March 5, 2009, 3:38pm UTC](https://www.ruby-forum.com/t/issue-with-the-object-cache/162054/3 "2009-03-05T15:38:55Z")

</div>

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 C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![luis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@luis](https://www.ruby-forum.com/u/luis)\
**Post date:** [March 5, 2009, 4:01pm UTC](https://www.ruby-forum.com/t/issue-with-the-object-cache/162054/4 "2009-03-05T16:01:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![luis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@luis](https://www.ruby-forum.com/u/luis)\
**Post date:** [March 5, 2009, 4:59pm UTC](https://www.ruby-forum.com/t/issue-with-the-object-cache/162054/5 "2009-03-05T16:59:04Z")

</div>

On Mar 5, 9:00 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![luis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@luis](https://www.ruby-forum.com/u/luis)\
**Post date:** [March 5, 2009, 5:41pm UTC](https://www.ruby-forum.com/t/issue-with-the-object-cache/162054/6 "2009-03-05T17:41:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![luis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@luis](https://www.ruby-forum.com/u/luis)\
**Post date:** [March 5, 2009, 5:03pm UTC](https://www.ruby-forum.com/t/issue-with-the-object-cache/162054/7 "2009-03-05T17:03:51Z")

</div>

On Thu, Mar 5, 2009 at 9:28 PM, luis [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.”

---

<div class="post-metadata">

**Author:** ![luis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3e96dc/32.png) [@luis](https://www.ruby-forum.com/u/luis)\
**Post date:** [March 5, 2009, 7:50pm UTC](https://www.ruby-forum.com/t/issue-with-the-object-cache/162054/8 "2009-03-05T19:50:52Z")

</div>

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
