NoMethodErrors

18 views
Skip to first unread message

Christian Aust

unread,
Jan 1, 2010, 4:20:06 PM1/1/10
to Thinking Sphinx
Hi all,

I'm using TS with Radiant, which causes me some trouble currently.
Actually I'm not sure if this is originally a problem of TS, or if
it's the radiant extension causing the error, but let me explain:

I've upgraded the TS gem to 1.3.14, and my application started to spit
out errors every now and then. Errors occur when I try to edit a page
that's a subclass of the ActiveRecord base class "Page", not a page
itself. There are two errors that I spotted so far:

> NoMethodError (undefined method `any?' for nil:NilClass):
> /usr/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.14/lib/thinking_sphinx/active_record/delta.rb:50:in `indexed_data_changed?'
> /usr/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.14/lib/thinking_sphinx/active_record/delta.rb:46:in `should_toggle_delta?'
> /usr/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.14/lib/thinking_sphinx/active_record/delta.rb:35:in `toggle_delta'
> vendor/extensions/reorder/lib/reorder/pages_controller_extensions.rb:7:in `send'
> vendor/extensions/reorder/lib/reorder/pages_controller_extensions.rb:7:in `move_lower'
> radiant (0.8.1) vendor/plugins/haml/rails/./lib/sass/plugin/rails.rb:19:in `process'

Theres another NoMethodError in active_record.rb:193 where the code
tries to add an index to self.sphinx_indexes which is nil sometimes,
which is easy to work around: I've added "unless
self.sphinx_indexes.nil?" at the end of the line and was fine so far.

Can somebody help me to understand whether this is something TS-
related or should I check the code of the Radiant extension? Kind
regards,

Christian

Pat Allan

unread,
Jan 2, 2010, 1:27:57 AM1/2/10
to thinkin...@googlegroups.com
Hi Christian

I think that might be the Radiant extension that's having problems - though I'm not certain.

sphinx_indexes is set when define_index is called - and so, this should happen when the model is loaded. The fact that it's no longer set suggests that it could be tied to cache_classes or something like that.

--
Pat

> --
>
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
>
>

Christian Aust

unread,
Jan 2, 2010, 3:29:46 AM1/2/10
to Thinking Sphinx
Hi Pat,

there's no too much code in that extension, basically it goes like
this:

When the extension loads, it executes this:

> def activate
> Page.send(:include, SphinxSearch::PageExtensions)
> # [...]
> end

The PageExtensions look like this:

> def self.included(base)
> base.define_index do
> set_property :delta => true, :group_concat_max_len => 8.kilobytes
> set_property :field_weights => { 'title' => 100 }
> indexes :title, parts.content
> indexes :tools, :roles, :duration, :customer
> has :updated_at, :status_id
> has :searchable, :type => :boolean
> end
> end

The errors occur with instances of classes that are a subclass of
Page, as if those instances of certain subclasses hadn't been
initialized properly. Is there something wrong with the way how
classes are extended by the code above? Regards,

Christian

On 2 Jan., 07:27, Pat Allan <p...@freelancing-gods.com> wrote:
> Hi Christian
>
> I think that might be the Radiant extension that's having problems - though I'm not certain.
>
> sphinx_indexes is set when define_index is called - and so, this should happen when the model is loaded. The fact that it's no longer set suggests that it could be tied to cache_classes or something like that.
>
> --
> Pat
>
> On 02/01/2010, at 8:20 AM, Christian Aust wrote:
>
>
>
> > Hi all,
>
> > I'm using TS with Radiant, which causes me some trouble currently.
> > Actually I'm not sure if this is originally a problem of TS, or if
> > it's the radiant extension causing the error, but let me explain:
>
> > I've upgraded the TS gem to 1.3.14, and my application started to spit
> > out errors every now and then. Errors occur when I try to edit a page
> > that's a subclass of the ActiveRecord base class "Page", not a page
> > itself. There are two errors that I spotted so far:
>
> >> NoMethodError (undefined method `any?' for nil:NilClass):
> >>  /usr/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.14/lib/thinking_sphinx/acti ve_record/delta.rb:50:in `indexed_data_changed?'
> >>  /usr/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.14/lib/thinking_sphinx/acti ve_record/delta.rb:46:in `should_toggle_delta?'

> >>  /usr/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.14/lib/thinking_sphinx/acti ve_record/delta.rb:35:in `toggle_delta'

Pat Allan

unread,
Jan 2, 2010, 11:00:23 PM1/2/10
to thinkin...@googlegroups.com
Hi Christian

Are you able to put together a sample app that reproduces this issue? I'm not sure if the fault is in Thinking Sphinx, Rails, or Radiant. Your extension seems simple enough, and isn't doing anything complex, so I very much doubt that's at fault.

If you can do this, feel free to send it to me off-list (or if you put it into GitHub, just give me read access).

Cheers

--
Pat

Josh French

unread,
Jan 4, 2010, 10:29:49 AM1/4/10
to Thinking Sphinx
Hi Christian,

This most likely has to do with the way AR subclasses are reloaded
between requests in dev mode, particularly with regards to included
modules. What version of Radiant are you using? Can you reproduce
these errors in production mode, or are they limited to development
mode? Is the pattern one or two successful page edits, followed by
errors?

There may be a way to make the Rails dependency loader more aware of
the PageExtensions module, I'd certainly take a patch if you wanted to
investigate.

Josh

On Jan 1, 4:20 pm, Christian Aust <datenimpera...@googlemail.com>
wrote:


> Hi all,
>
> I'm using TS with Radiant, which causes me some trouble currently.
> Actually I'm not sure if this is originally a problem of TS, or if
> it's the radiant extension causing the error, but let me explain:
>
> I've upgraded the TS gem to 1.3.14, and my application started to spit
> out errors every now and then. Errors occur when I try to edit a page
> that's a subclass of the ActiveRecord base class "Page", not a page
> itself. There are two errors that I spotted so far:
>
> > NoMethodError (undefined method `any?' for nil:NilClass):

> >   /usr/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.14/lib/thinking_sphinx/acti ve_record/delta.rb:50:in `indexed_data_changed?'
> >   /usr/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.14/lib/thinking_sphinx/acti ve_record/delta.rb:46:in `should_toggle_delta?'

> >   /usr/lib/ruby/gems/1.8/gems/thinking-sphinx-1.3.14/lib/thinking_sphinx/acti ve_record/delta.rb:35:in `toggle_delta'

Christian Aust

unread,
Jan 5, 2010, 3:43:18 AM1/5/10
to Thinking Sphinx
Hi Pat & Josh,

that's fairly easy to reproduce, detailled steps are on gist:

http://gist.github.com/269247

Even the rake task of setting up TS crashes. Any idea? Kind regards,

Christian

Pat Allan

unread,
Jan 5, 2010, 7:23:45 AM1/5/10
to thinkin...@googlegroups.com
Thanks for that Christian - I was able to reproduce the issue. Now I just need to find some time to figure out why it's happening :)

--
Pat

John Polling

unread,
Jan 6, 2010, 5:12:20 AM1/6/10
to Thinking Sphinx
Hi,

I'm having this same problem also. Interestingly I have other models
being indexed by TS such as a news and events models, and they are
indexing fine within the same radiant app. As soon as I remove the
Page define_index method the ts:index and search results work fine.

I've tried tweaking the define_index method in the PageExtensions
module, but nothing seems to fix the problem.

Regards

John

Josh French

unread,
Jan 6, 2010, 9:43:08 AM1/6/10
to Thinking Sphinx
Something is amiss, your gist works just fine for me. Let's be sure
everyone's on the same page -- I'm running:

Radiant 0.8.1
Sphinx 0.9.8.1
Thinking Sphinx 1.3.14
Will Paginate 2.3.11 (From gemcutter, although the github mislav-
version also worked for me)

Does that differ from your environment?

j

On Jan 5, 3:43 am, Christian Aust <datenimpera...@googlemail.com>
wrote:

John Polling

unread,
Jan 6, 2010, 2:55:25 PM1/6/10
to Thinking Sphinx
I'm running on on the same environment, including the latest version
of the radiant sphinx_search extension.

John

Christian Aust

unread,
Jan 6, 2010, 5:11:39 PM1/6/10
to Thinking Sphinx
Very same setup of gems here. Still, it doesn't work.

To be sure, I set up a fresh instance of Ubuntu 9.10, installed ruby
and rubygems and mysql and sphinx and rails and gemcutter and ...

[you get it, I found it surprisingly hard to install radiant on a
fresh machine, took me 10 minutes for Ubuntu and 60 minutes to figure
out the gem dependency errors]

... in the end, I got the very same error that I described above.
"rake thinking_sphinx:rebuild --trace" doesn't even run. Same error
message as described in my gist.

I assume it has something to do with "virtual" pages. I see that when
I have eg Archive pages involved in the site, that's why I chose the
template including the blog and archives. Regards,

Christian

John Polling

unread,
Jan 7, 2010, 12:28:11 AM1/7/10
to Thinking Sphinx
I'm also using plenty of virtual pages.

On Jan 6, 10:11 pm, Christian Aust <datenimpera...@googlemail.com>
wrote:

Josh French

unread,
Jan 7, 2010, 12:38:18 PM1/7/10
to Thinking Sphinx
OK, got it. The various Archive subclasses are stored as an extension
inside core Radiant. The archive extension is loading before sphinx-
search, so those Page subclasses are loaded before Thinking Sphinx is
injected into their base class. At that point it's too late for any
already-loaded subclasses to inherit the behavior.

The workaround: load sphinx-search before archives. In config/
environment.rb:

config.extensions = [:sphinx_search, :all]

I'll update the extension docs to reflect this. Let me know if you're
still having trouble with it.

Best,
Josh

On Jan 7, 12:28 am, John Polling <john.pollin...@googlemail.com>
wrote:

Pat Allan

unread,
Jan 7, 2010, 7:03:27 PM1/7/10
to thinkin...@googlegroups.com
Ah, great detective work Josh :)

--
Pat

Christian Aust

unread,
Jan 8, 2010, 8:48:56 AM1/8/10
to Thinking Sphinx
Great, thanks a lot. Simple as that, I didn't expect such a solution.

However, I started playing around with the config.extensions directive
because of the file_system extension, which demands to be loaded last
in the chain. So I'd have two requirements already, TS first and
file_system last. Any chance to change the code of sphinx-search in a
way to get rid of at least one of those requirements, before some
other code comes and requires to be loaded first? Regards,

Christian

Josh French

unread,
Jan 8, 2010, 2:09:36 PM1/8/10
to Thinking Sphinx
> Any chance to change the code of sphinx-search in a
> way to get rid of at least one of those requirements

Not really, unfortunately. I'd just end up creating the same kind of
load-order problem for someone else's extension. In your case, you
could do:

config.extensions = [:sphinx_search, :all, :file_system]

What's important is that sphinx_search get loaded before any
extensions that add Page subclasses, not that it come strictly first.
So you've got some leeway in how you order your extensions.

j

Josh French

unread,
Jan 8, 2010, 6:32:02 PM1/8/10
to Thinking Sphinx
I've given this a ponder and there may be a workaround, although I'll
need Pat or someone else with a better knowledge of Sphinx internals
to weigh in.

Are there any disadvantages to moving from something like this:

Page.class_eval do
include IndexDefinition
end

...to something like this?

[Page, *Page.subclasses].each do |klass
klass.class_eval do
include IndexDefinition
end
end

This way any pre-loaded subclasses get the behavior as well, but I'm
not sure if defining multiple indexes like this will interfere with
TS's own subclass handling.

Any insight?

Thanks,
j

Pat Allan

unread,
Jan 10, 2010, 6:09:12 PM1/10/10
to thinkin...@googlegroups.com
Hi Josh

Probably best to not do that, because then you'll be defining multiple indexes on the subclasses, and Sphinx might find that a tad confusing. Thinking Sphinx too, for that matter.

--
Pat

Reply all
Reply to author
Forward
0 new messages