Hobo and STI does not work with ruby 1.9.2
Reported by Betelgeuse | November 1st, 2010 @ 07:21 PM | in Hobo 1.0X
http://github.com/tablatom/hobo/commit/67b3a23addc73bb5578220bad6b3...
Seems we are fixing ruby 1.9.2 so thought about reporting that last time I tried STI did not work because of changes in how super behaves. I don't have info for that any more but can dig if needed to reproduce.
Comments and changes to this ticket
-
Bryan Larsen November 1st, 2010 @ 07:39 PM
A failing test case would be nice. I hope to get the overdue 1.0.2 out in the next few days.
-
Betelgeuse November 1st, 2010 @ 08:00 PM
** Execute environment rake aborted! super from singleton method that is defined to multiple classes is not supported; this will be fixed in 1.9.3 or later /Users/betelgeuse/.rvm/gems/ruby-1.9.2-p0/gems/hobofields-1.0.1/lib/hobo_fields/model_extensions.rb:30:in `inherited'
Hopefully there's nothing specific to my project involved so it should manifest itself by just creating a STI setup.
-
Bryan Larsen November 15th, 2010 @ 09:11 PM
- State changed from new to open
- Milestone set to Hobo 1.0X
- Tag set to compatibility
- Milestone order changed from 197913 to 0
-
Bryan Larsen November 15th, 2010 @ 10:43 PM
I just forward ported an old app that uses STI and was able to reproduce the problem.
-
Domizio Demichelis November 15th, 2010 @ 10:50 PM
could you please try to apply this patch
diff --git a/hobo/lib/hobo/model.rb b/hobo/lib/hobo/model.rb index 989d1fc..39331c8 100644 --- a/hobo/lib/hobo/model.rb +++ b/hobo/lib/hobo/model.rb @@ -25,22 +25,22 @@ module Hobo include FindFor include AccessibleAssociations include IncludeInSave - end - - class << base - alias_method_chain :belongs_to, :creator_metadata - alias_method_chain :belongs_to, :test_methods - alias_method_chain :attr_accessor, :creator_metadata - - alias_method_chain :has_one, :new_method - def inherited(klass) + def self.inherited(klass) super fields(false) do Hobo.register_model(klass) field(klass.inheritance_column, :string) end end + + end + + class << base + alias_method_chain :belongs_to, :creator_metadata + alias_method_chain :belongs_to, :test_methods + alias_method_chain :attr_accessor, :creator_metadata + alias_method_chain :has_one, :new_method end base.fields(false) # force hobo_fields to load
I don't know whether it works on your branch, since it is from the rails3 branch, but it's so simple that you can also apply it manually in 10 secs.
Please, let me know.
-
Bryan Larsen November 16th, 2010 @ 01:23 PM
Thanks Domizio, but that patch doesn't help. For me, the problem appears in hobo_fields/model_extensions.rb. Maybe once I fix that, your patch will help avoid another instance of the same problem.
-
Domizio Demichelis November 16th, 2010 @ 01:36 PM
I see: class << self is the problem.
We could define the methods as def self.method and get rid of the singleton class, or when it is a module, we can use extend self and that should avoid the singleton without the need of defining everything with self.
Anyway, it's a temporay problem and it will get fixed by itself with the nex ruby version.
ciao
dd -
Bryan Larsen November 16th, 2010 @ 01:57 PM
This patch seems to fix this problem for me:
diff --git a/hobofields/lib/hobo_fields/model_extensions.rb b/hobofields/lib/hobo_fields/model_extensions.rb index 8459140..7fa0285 100644 --- a/hobofields/lib/hobo_fields/model_extensions.rb +++ b/hobofields/lib/hobo_fields/model_extensions.rb @@ -27,7 +27,7 @@ module HoboFields f.field(inheritance_column, :string) end index(inheritance_column) - super + ActiveRecord::Base.inherited(klass) end def self.index(fields, options = {})
It's hard to tell -- I've got other problems because its an old app. Betelgeuse, can you try the patch and see if it fixes your app?
Obviously that's just a hack patch, but it does let us know what has to be fixed...
-
Domizio Demichelis November 16th, 2010 @ 03:20 PM
yes, it's not quite the same as super since it would bypass any defined inherited of the class, but we could find the super method first and then call it directly to avoid any possible problem.
Someone reported the problem generated in the hobo model, so my patch (possibly improved a little) should be also needed. I did a search for 'super' and it seems that it is called from a singleton only in that 2 places, (most calls are from initialize), so we probably can fix it with both (improved) patches.
-
Bryan Larsen November 18th, 2010 @ 09:07 PM
I got more of my app working, and it appears to be fine, although it could certainly use more testing.
Here's a patch that's more complete, although definitely not pretty. Comments?
diff --git a/hobofields/lib/hobo_fields/model_extensions.rb b/hobofields/lib/hobo_fields/model_extensions.rb index 8459140..7c8a17e 100644 --- a/hobofields/lib/hobo_fields/model_extensions.rb +++ b/hobofields/lib/hobo_fields/model_extensions.rb @@ -27,7 +27,12 @@ module HoboFields f.field(inheritance_column, :string) end index(inheritance_column) - super + # this snippet is here because "super" doesn't work on Ruby 1.9.2. See Lighthouse #840. + klass.ancestors.each do |kls| + if kls.respond_to?(:inherited) && !kls.include?(ModelExtensions) + kls.inherited(klass) + end + end end def self.index(fields, options = {})
-
Bryan Larsen November 23rd, 2010 @ 03:38 AM
Neither patch actually works.
class A < ActiveRecord::Base hobo_model fields do name :string sti_type :string end set_inheritance_column :sti_type belongs_to :user end class B < A hobo_model end
With either patch,
B.reflections => {}
. Running without a patch I either get a crash (on 1.9.2), or I get the :user (on other versions). -
Domizio Demichelis November 26th, 2010 @ 04:10 AM
(from [590d0874ba4974ffae613855387bbdca51dd2875]) fix for ruby 1.9.2 dreadful "super from singleton method" error [#840] https://github.com/tablatom/hobo/commit/590d0874ba4974ffae613855387...
-
Domizio Demichelis November 26th, 2010 @ 04:11 AM
- Assigned user set to Bryan Larsen
-
Domizio Demichelis November 26th, 2010 @ 09:21 PM
(from [af9d600e85afe2db447b561de48d6063dd8a11cf]) added comments for 1.9.2 error and fix indentation of eval string [#840] [#869] https://github.com/tablatom/hobo/commit/af9d600e85afe2db447b561de48...
-
Bryan Larsen November 27th, 2010 @ 04:07 AM
(from [e2bbe6a1ce856b6864f78f15ffd469d7a8a1661b]) [#840] avoid the 1.9.2 "super from singleton method" error https://github.com/tablatom/hobo/commit/e2bbe6a1ce856b6864f78f15ffd...
-
Bryan Larsen November 27th, 2010 @ 04:07 AM
(from [42b9472ff65410d35b448e77c1041c2e42af980a]) [#840] avoid the 1.9.2 "super from singleton method" error https://github.com/tablatom/hobo/commit/42b9472ff65410d35b448e77c10...
-
Domizio Demichelis November 27th, 2010 @ 02:46 PM
(from [59ab7aa4dd78fd2eed8a561598c07ff4fdc57617]) another fix for ruby 1.9.2 "super from singleton method" error [#840] https://github.com/tablatom/hobo/commit/59ab7aa4dd78fd2eed8a561598c...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
People watching this ticket
Tags
Referenced by
- 869 hobo_create broken on ruby 1.9.2 and 1.3.0.pre19 see also ticket #840 for similar problem and potential so...
- 869 hobo_create broken on ruby 1.9.2 and 1.3.0.pre19 Indeed as I have also filed #840 :)
- 840 Hobo and STI does not work with ruby 1.9.2 (from [590d0874ba4974ffae613855387bbdca51dd2875]) fix for...
- 869 hobo_create broken on ruby 1.9.2 and 1.3.0.pre19 (from [590d0874ba4974ffae613855387bbdca51dd2875]) fix for...
- 869 hobo_create broken on ruby 1.9.2 and 1.3.0.pre19 (from [af9d600e85afe2db447b561de48d6063dd8a11cf]) added c...
- 840 Hobo and STI does not work with ruby 1.9.2 (from [af9d600e85afe2db447b561de48d6063dd8a11cf]) added c...
- 840 Hobo and STI does not work with ruby 1.9.2 (from [e2bbe6a1ce856b6864f78f15ffd469d7a8a1661b]) [#840] ...
- 840 Hobo and STI does not work with ruby 1.9.2 (from [42b9472ff65410d35b448e77c1041c2e42af980a]) [#840] ...
- 840 Hobo and STI does not work with ruby 1.9.2 (from [59ab7aa4dd78fd2eed8a561598c07ff4fdc57617]) another...