Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

raise_on_type_mismatch : expected User, got User

#229

This issue is more than a year old and already extensively discussed at http://dev.rubyonrails.org/ticke....

Basically: when you have a model that has an association with another model that is part of a plugin, and on the second request your model gets reloaded in the development environment while the model in the plugin doesn't get reloaded, then assigning a new value to the association will result in an error like:

ActiveRecord::AssociationTypeMismatch: User expected, got User

Attached is a patch including a test to prove this case.

Reported by Lawrence Pit · May 21st, 2008 @ 02:49 AM

State: resolved
Milestone: none
Assigned to: Pratik Pratik
Importance: Low

Activity

  1. Roger
    Roger

    add me as a user wishing this patch were applied.

    May 21st, 2008 @ 03:00 AM

  2. Pratik
    Pratik
    • State changed from new to invalid

    May 21st, 2008 @ 10:27 AM

  3. Lawrence Pit
    Lawrence Pit

    @Pratik : I suggest you look closer at my patch. It actually takes care of NOT showing the error message, something that ticket #189 ActiveRecord::AssociationTypeMismatch with same class name -- added helpful e... does not do.

    May 21st, 2008 @ 12:11 PM

  4. Pratik
    Pratik

    Yes I noticed.

    1. The tests pass even without the patch. Also, the patch is in wrong directory. Should be in ar/test/cases/

    2. Not really in favor of putting eval stuff. I.e. magically reloading plugin model.

    3.People should just make plugins reloadable instead.

    Thanks.

    May 21st, 2008 @ 12:24 PM

  5. Roger
    Roger

    I wonder if it couldn't use something like

    if is_a?(klass) or is_a?(eval(klass)) # only use the eval as a backup...

    -R

    May 21st, 2008 @ 05:05 PM

  6. Lawrence Pit
    Lawrence Pit

    @Roger that is what it's doing, it's only used as a backup

    @Pratik the test was in the wrong dir, I've attached two new files: one with the test, one with the patch. If you run the test it does NOT pass without the patch.

    May 21st, 2008 @ 10:55 PM

  7. Lawrence Pit
  8. vamsee
    vamsee
    • Assigned user set to Pratik
    • Tag set to activerecord, patch, tests

    Please add Lawrence's patch to core. This problem still comes up, and the above patch solves it. Ticket no. #189 ActiveRecord::AssociationTypeMismatch with same class name -- added helpful e... only displays the error properly, but does not fix it.

    August 31st, 2008 @ 08:45 AM

  9. Luke Sheridan
    Luke Sheridan

    Thank you for this patch Lawrence, the error was driving me nuts!

    October 2nd, 2008 @ 03:56 AM

  10. Pratik
    Pratik
    • State changed from invalid to open

    October 2nd, 2008 @ 11:23 AM

  11. Repository
    Repository
    • State changed from open to resolved

    (from [7659fb6a2b638703a99a63033d947d19089a6b85]) Try reloading model on class mismatch [#229 raise_on_type_mismatch : expected User, got User state:resolved]

    Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...

    October 4th, 2008 @ 05:51 PM

  12. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    October 12th, 2010 @ 09:06 AM

  13. Anil Wadghule
    Anil Wadghule

    Automatic cleanup of spam.

    October 12th, 2010 @ 09:10 AM

  14. Anil Wadghule
    Anil Wadghule

    Automatic cleanup of spam.

    October 12th, 2010 @ 09:10 AM

  15. Anil Wadghule
    Anil Wadghule

    Automatic cleanup of spam.

    October 12th, 2010 @ 09:10 AM

  16. Anil Wadghule
    Anil Wadghule

    Automatic cleanup of spam.

    October 12th, 2010 @ 09:11 AM

  17. Aditya Sanghi
    Aditya Sanghi

    Automatic cleanup of spam.

    October 12th, 2010 @ 10:15 AM

  18. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 13th, 2010 @ 06:25 AM