drnic/composite_primary_keys — Issue #79: Rails 3.2 RC2 throwing "stack level too deep (SystemStackError)" when model_instance.inspect is called.
Author: newtonapple
Created: 2012-01-11 05:57:36+00:00
State: open

I know Rails 3.2 is still in RC2. But, when it's released I think others will definitely run into this problem. I reproduced this error in an existing app I was trying to upgrade from Rails 3.1 as well a new test app. Here is a simple user model:

```ruby
# app/models/user.rb
class User < ActiveRecord::Base
end

# db/migrate/create_users.rb
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.timestamps
end
end
end
```

```bash
rake db:migrate
rails -r "User.create :name => 'user1'"
rails -r "puts User.first.inspect'" # throws stack level too deep (SystemStackError)
```

It generates the following warning message in development log:

DEPRECATION WARNING: You have called '_id'. This is deprecated. Please use either 'id' or read_attribute('id'). (called from at (eval):1)
DEPRECATION WARNING: The method `_id', matching the attribute `id' has dispatched through method_missing. This shouldn't happen, because `id' is a column of the table. If this error has happened through normal usage of Active Record (rather than through your own code or external libraries), please report it as a bug. (called from at (eval):1)
DEPRECATION WARNING: You have called '_id'. This is deprecated. Please use either 'id' or read_attribute('id'). (called from at (eval):1)

From a quick investigation, the problem seems to be in composite_primary_keys' ActiveRecord::AttributeMethods::Read#read_attribute.