Strange error: QtRuby and AR (sqlite3)

H

Hans Fugal

I'm developing a recipe app for my wife using ActiveRecord (with
sqlite3) and QtRuby. It "works" on my iBook, but when I try to test it
on my Debian sarge box I get the following:

/usr/local/lib/site_ruby/1.8/rubygems.rb:172:in `method_missing':
unresolved method call (ArgumentError)
from /usr/local/lib/site_ruby/1.8/rubygems.rb:172:in `activate'
from /usr/local/lib/site_ruby/1.8/rubygems.rb:171:in `each'
from /usr/local/lib/site_ruby/1.8/rubygems.rb:171:in `activate'
from
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:23:in `require'
from
/usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/dependencies.rb:200:in
`require'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:10:in
`require_library_or_gem'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/sqlite_adapter.rb:15:in
`sqlite3_connection'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/query_cache.rb:52:in
`send'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/query_cache.rb:52:in
`connection='
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/connection_adapters/abstract_adapter.rb:108:in
`retrieve_connection'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:239:in
`connection'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:751:in
`add_limit!'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:746:in
`construct_finder_sql'
from
/usr/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/base.rb:343:in
`find'
from ./lib/neelix/view/qt.rb:31:in `initialize'
from /home/fugalh/src/neelix/bin/neelix:15:in `new'
from /home/fugalh/src/neelix/bin/neelix:15

Line 31 of qt.rb is simply

recipes = Recipe.find:)all)

which doesn't really match the error at all.

ActiveRecord is installed via gems, and rails on this box is working
fine (lam.fugal.net - also using sqlite3). QtRuby is installed by hand
(version 1.0.9) and it works fine as well. When I fire up irb and load
everything but the gui by hand I can see and use the db via AR just
fine. I'm completely confounded, and I think it might be something
deeper like maybe QtRuby and gems (or at least the AR version from
gems) not playing nicely, even though it works fine on my laptop.
(There I also have qtruby from hand, AR and sqlite3 from gem)
 
J

Jacob Fugal

I'm developing a recipe app for my wife using ActiveRecord (with
sqlite3) and QtRuby. It "works" on my iBook, but when I try to test it
on my Debian sarge box I get the following:

/usr/local/lib/site_ruby/1.8/rubygems.rb:172:in `method_missing':
unresolved method call (ArgumentError)

Having the luxury of access to Hans' development environment, I
tracked this down. It was a nasty little bugger, and eventually the
fault of QtRuby, but the patch here[1] is against rubygems to help
gems protect itself against other libraries making mistakes like this.

The code in question is from rubygems.rb:

# Now add the require_paths to the LOAD_PATH
spec.require_paths.each do |path|
$:.unshift File.join(spec.full_gem_path, path)
end

The middle line was throwing the error. Seems really odd for a
method_missing error to show up there, right? $:, File and the gemspec
are all known quantities... or so we thought.

What had happened was that somehow Qt::File had been imported into the
current namespace and occluded ::File from core. When Hans' code tried
to load a gem, the gems code ended up trying to call Qt::File.join,
rather than ::File.join. Qt::File doesn't have a join method, but does
handle missing methods in exactly the manner shown in Hans' error.

The morals of the story?

1) Don't occlude core libraries
2) Use super as the default behavior for method_missing

Regarding 2, if Qt::*'s implementation of method_missing were to
bounce up to super when a suitable replacement could not be found, the
error probably would have looked something like "NoMethodError:
undefined method `join' for Qt::File:Module", rather than the
singularly unhelpful "unresolved method call (ArgumentError)". The
error would have made it abundantly clear what the problem actually
was.

Jacob Fugal

[1] Patch follows:

--- /tmp/rubygems.rb.old 2005-10-18 11:43:11.000000000 -0600
+++ /usr/local/lib/site_ruby/1.8/rubygems.rb 2005-10-18
11:43:32.000000000 -0600
@@ -169,7 +169,7 @@

# Now add the require_paths to the LOAD_PATH
spec.require_paths.each do |path|
- $:.unshift File.join(spec.full_gem_path, path)
+ $:.unshift ::File.join(spec.full_gem_path, path)
end

require spec.autorequire if autorequire && spec.autorequire
 
H

Hans Fugal

Thanks again, Jacob. I know some of you are going to ask, so here's the
preemptive answer: No, I do not "include 'Qt'" anywhere in my code. You
are welcome to look for yourself: http://hans.fugal.net/src/neelix

qtruby folks, are you listening, or should I submit a bug on some bug
tracker somewhere?
 
R

Richard Dale

Hans said:
Thanks again, Jacob. I know some of you are going to ask, so here's the
preemptive answer: No, I do not "include 'Qt'" anywhere in my code. You
are welcome to look for yourself: http://hans.fugal.net/src/neelix

qtruby folks, are you listening, or should I submit a bug on some bug
tracker somewhere?
It's possible that this has already been fixed in the version of QtRuby that
Caleb Tennis has recently released on RubyForge (or part of the forthcoming
KDE 3.5 release). The QtRuby code used to have an 'include Qt' in it, which
messed up the Qt:: namespace.

-- Richard
 
H

Hans Fugal

That would be 1.0.10 right? I tried that one (on my mac) and had
trouble with it (a missing file and a bad file, or something... I told
Caleb by email). I might have to give it a try on my linux box,
although at the moment with my patched rubygems.rb I'm in no hurry.
Glad to hear it's been taken care of.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top