This project is archived and is in readonly mode.
raise_on_type_mismatch : expected User, got User
Reported by Lawrence Pit | May 21st, 2008 @ 02:49 AM
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.
Comments and changes to this ticket
-
Pratik May 21st, 2008 @ 10:27 AM
- State changed from new to invalid
Duplicate of http://rails.lighthouseapp.com/p...
-
Lawrence Pit May 21st, 2008 @ 12:11 PM
@Pratik : I suggest you look closer at my patch. It actually takes care of NOT showing the error message, something that ticket #189 does not do.
-
Pratik May 21st, 2008 @ 12:24 PM
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.
-
Roger May 21st, 2008 @ 05:05 PM
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
-
Lawrence Pit May 21st, 2008 @ 10:55 PM
@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.
-
Lawrence Pit May 21st, 2008 @ 10:55 PM
- no changes were found...
-
vamsee August 31st, 2008 @ 08:45 AM
- 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 only displays the error properly, but does not fix it.
-
Luke Sheridan October 2nd, 2008 @ 03:56 AM
Thank you for this patch Lawrence, the error was driving me nuts!
-
Pratik October 2nd, 2008 @ 11:23 AM
- State changed from invalid to open
-
Repository October 4th, 2008 @ 05:51 PM
- State changed from open to resolved
(from [7659fb6a2b638703a99a63033d947d19089a6b85]) Try reloading model on class mismatch [#229 state:resolved]
Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...
-
Jeff Kreeftmeijer October 12th, 2010 @ 09:06 AM
- Tag cleared.
- Importance changed from to Low
Automatic cleanup of spam.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 189 ActiveRecord::AssociationTypeMismatch with same class name -- added helpful exception message See #229 if you still experience issues with this.
- 229 raise_on_type_mismatch : expected User, got User (from [7659fb6a2b638703a99a63033d947d19089a6b85]) Try rel...