Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

calling model.dup with ruby 2.0.0 calls private method #9417

Closed
phoet opened this Issue Feb 25, 2013 · 16 comments

Comments

Projects
None yet
8 participants
Contributor

phoet commented Feb 25, 2013

switching my rails 3.2.12 project to ruby 2.0.0 fails a test:

NoMethodError:
  private method `initialize_dup' called for #<Event:0x007fe06c809428>

this is the code that gets called: https://github.com/phoet/on_ruby/blob/master/app/models/event.rb#L86

looks like initialize_dup is now a private method :sadpanda:

Member

sikachu commented Feb 25, 2013

Would you mind pasting in the whole stack trace?

Contributor

phoet commented Feb 25, 2013

rspec swallows a lot of it, but this is the stack from the rails console:

NoMethodError: private method `initialize_dup' called for #<Event:0x007fed83101c60>
    from /Users/paule/.rvm/gems/ruby-2.0.0-p0@on_ruby/gems/activemodel-3.2.12/lib/active_model/attribute_methods.rb:404:in `method_missing'
    from /Users/paule/.rvm/gems/ruby-2.0.0-p0@on_ruby/gems/activerecord-3.2.12/lib/active_record/attribute_methods.rb:149:in `method_missing'
    from /Users/paule/.rvm/gems/ruby-2.0.0-p0@on_ruby/gems/activemodel-3.2.12/lib/active_model/validations.rb:179:in `dup'
    from /Users/paule/.rvm/gems/ruby-2.0.0-p0@on_ruby/gems/activerecord-3.2.12/lib/active_record/base.rb:562:in `dup'
    from /Users/paule/Documents/rails/on_ruby/app/models/event.rb:86:in `duplicate!'
    from (irb):1
    from /Users/paule/.rvm/gems/ruby-2.0.0-p0@on_ruby/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
    from /Users/paule/.rvm/gems/ruby-2.0.0-p0@on_ruby/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
    from /Users/paule/.rvm/gems/ruby-2.0.0-p0@on_ruby/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
Member

sikachu commented Feb 25, 2013

It's indeed a legit bug. Do you want to submit a pull request with a test case for this?

$ rails c
Loading development environment (Rails 3.2.12)
irb(main):001:0> User.create name: 'foo'
   (0.0ms)  begin transaction
  SQL (3.4ms)  INSERT INTO "users" ("created_at", "name", "updated_at") VALUES (?, ?, ?)  [["created_at", Mon, 25 Feb 2013 16:00:43 UTC +00:00], ["name", "foo"], ["updated_at", Mon, 25 Feb 2013 16:00:43 UTC +00:00]]
   (0.7ms)  commit transaction
=> #<User id: 1, name: "foo", created_at: "2013-02-25 16:00:43", updated_at: "2013-02-25 16:00:43">
irb(main):002:0> User.first.dup
  User Load (0.2ms)  SELECT "users".* FROM "users" LIMIT 1
NoMethodError: private method `initialize_dup' called for #<User name: "foo", created_at: nil, updated_at: nil>
    from /Users/sikachu/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.12/lib/active_model/attribute_methods.rb:404:in `method_missing'
    from /Users/sikachu/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.12/lib/active_record/attribute_methods.rb:149:in `method_missing'
    from /Users/sikachu/.rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.12/lib/active_model/validations.rb:179:in `dup'
    from /Users/sikachu/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.12/lib/active_record/base.rb:562:in `dup'
    from (irb):2
    from /Users/sikachu/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
    from /Users/sikachu/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
    from /Users/sikachu/.rvm/gems/ruby-2.0.0-p0/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
irb(main):003:0> 

@ghost ghost assigned sikachu Feb 25, 2013

Contributor

phoet commented Feb 25, 2013

sure, give me a minute

Contributor

flop commented Feb 25, 2013

Seems to be the same thing as #7291
It's merged in 3-2-stable but it has not been released yet

Contributor

phoet commented Feb 25, 2013

that would explain why i am not able to reproduce the error in the tests 😄

Member

sikachu commented Feb 25, 2013

Oh, good call. Since that was merged, I'm closing this. Thanks guys! :D

@sikachu sikachu closed this Feb 25, 2013

Member

sikachu commented Feb 25, 2013

(Oh, and I'll make sure we get another 3.2.x RC soon. 😄)

n8gard commented Feb 25, 2013

I just got this too. Rails 3.2.12 and Ruby 2.0.0-p0.

Member

sikachu commented Feb 25, 2013

@njnorrgard please wait for 3.2.13 or point your Gemfile to 3-2-stable for now.

Any idea when this will get released? Its the only thing in Rails that breaks for me with Ruby 2.0

Yes, 3.2.13.rc2 is the version to use with 2.0, the final 3.2.13 should be released soon.

Works perfectly. Thanks!

@ageweke ageweke pushed a commit to ageweke/low_card_tables that referenced this issue Nov 2, 2013

Andrew Geweke AR 3.1.12 is incompatible with Ruby 2.0.0 (rails/rails#9417); test ag…
…ainst SQLite, too.
e530ab3

jrep commented Jan 10, 2014

This seems to be back again, using Ruby 2.1.0, Rails 4.0.2 . See StackOverflow

Owner

pixeltrix commented Jan 12, 2014

@jrep sorry, that question is something entirely unrelated - did you link to the wrong question or post in the wrong GH issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment