Set STI type column correctly when calling becomes! #13272

wants to merge 1 commit into


None yet

5 participants


The becomes! method is currently broken and need to be called a second time to correctly set the type column when changing from the base model to a sub-class.


You need to add a test case for this kind of change.
Also, having an unless like this inside a method call isn't readable. Could you split it in two lines?

if klass.descends_from_active_record?
  sti_name = nil
  sti_name = klass.sti_name
became.public_send("#{klass.inheritance_column}=", sti_name)

My point was to raise awareness of this issue and suggest a way that it can be fixed, not necessarily supply the final patch.

I'm also unsure how to setup an environment for running the test suite locally. Does it matter whether I'm using rbenv or rvm? Do I need mysql installed as I only ever develop against postgresql, etc.


There's a good guide which should help you: contributing to ruby on rails.


Ran into this issue recently myself, I'll see about adding test case(s) over the weekend.

@senny senny closed this in e95031f Jan 13, 2014
@senny senny added a commit that referenced this pull request Jan 13, 2014
@senny senny fix bug in becomes! when changing from base to subclass. Closes #13272.
Ruby on Rails member

patch applied and backported to 4-0-stable. @the-web-dev thanks for bringing this up.

@tenderlove tenderlove added a commit that referenced this pull request Jan 17, 2014
@tenderlove tenderlove Merge branch 'master' into set_binds
* master: (24 commits)
  unscope should remove bind values associated with the where
  reverse_order_value= is not private, so no need to send
  avoid more dynamic symbols
  no need to to_sym
  recover from test runs that leave the database in a bad state
  updates screenshot data [ci skip]
  "serie" => "series"
  revises a few things in the getting started guide [ci skip]
  Favor canonical environment variables for secrets
  removed extra comma [ci skip]
  Only lookup `config.log_level` for stdlib `::Logger`. Closes #11665.
  Updated Changelog to reflect removal of :dependent => :restrict
  standardize on jruby_skip & rbx_skip
  fix bug in becomes! when changing from base to subclass. Closes #13272.
  highlight http://localhost:3000 in Closes #13643. [ci skip]
  doc proc/lambda arg on inclusion validation. Closes #13689. [ci skip]
  Skip Spring App Generator tests on JRuby
  fixes a typo in a CHANGELOG
  upgrade SDoc
  fixes the Gemfile generator templates


I'm still having this issue in 4.2:

rails (4.2.0)
      actionmailer (= 4.2.0)
      actionpack (= 4.2.0)
      actionview (= 4.2.0)
      activejob (= 4.2.0)
      activemodel (= 4.2.0)
      activerecord (= 4.2.0)
      activesupport (= 4.2.0)
      bundler (>= 1.3.0, < 2.0)
      railties (= 4.2.0)

Hmmm, looks like adding Carrierwave was what caused this bug to come back for me (it worked before adding it). Looking at the Gemfile I see this:

carrierwave (0.10.0)
      activemodel (>= 3.2.0)
      activesupport (>= 3.2.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment