Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model.import causes stack level too deep error #144

Closed
tomciopp opened this issue Jun 13, 2014 · 13 comments
Closed

Model.import causes stack level too deep error #144

tomciopp opened this issue Jun 13, 2014 · 13 comments

Comments

@tomciopp
Copy link

Currently when I try to use the import class method provided by elasticsearch-model, I run into SystemStackError: stack level too deep. It looks like it runs into an error in irb and pry when they try to run eval on the code. This causes errors to occur in the rake tasks as well. I am running version 3.2.16 of ActiveRecord.

@karmi
Copy link
Contributor

karmi commented Jun 16, 2014

@tomciopp That would be really surprising, since there's lot of integration tests for the feature.

(...) when they try to run eval on the code (...)

Don't know what you mean, but I use the import method in Rails console and Pry quite frequently. It would be good if you provide info on what exactly you're doing and all the stacktraces!

@tomciopp
Copy link
Author

It looks like the error was on my side. One of the classes in an application I am working on did not follow the convention for naming in rails. Fixing this issue also fixed the issues I was having with Model.import.

@arfl
Copy link

arfl commented Dec 17, 2014

We also get this error! This is caused by rails single table inheriance:
Consider the following situation:

class A < ActiveRecord::Base
  include Elasticsearch::Model
end

class B < A

end

class C < A

end

# then if you try to import the jobs you get the error described above
B.import
C.import

A.import # works

@stepankuzmin
Copy link

I've the same issue as @arfl described

@salmanzameer
Copy link

@karmi @arfl @stepankuzmin any updates on this problem with STI ?

Did any of you get any chance to resolve it. Also if you can share some gist for STI search would be great. I am have very hard time with it.

Previously, I was working with tire and it was working like a charm.

@karmi
Copy link
Contributor

karmi commented Feb 23, 2015

I'll try to look into that later in the month, focused on something else right now, sorry!

@jxodwyer
Copy link

I'm also hitting the same issue that @arfl called out. Look forward to seeing what you come up with @karmi . Thanks for the help!

@jlaw90
Copy link

jlaw90 commented Mar 14, 2015

Hi guys,

I had this same issue in an abstract base class, by instead doing instance_eval on the subclass fixed it.

I added the following method:

  def self.inherited(child)
    super

    child.instance_eval do
      # Elastic search functionality!
      include Elasticsearch::Model

      # Automatically update the index on change
      include Elasticsearch::Model::Callbacks
    end
  end

@stepankuzmin
Copy link

Thanks @jlaw90, your code solved this issue for me.

@karmi
Copy link
Contributor

karmi commented Mar 17, 2015

Thanks for the code eample, @jlaw90! Do you have an idea how we could address this in the gem, either in code or the documentation?

There are too many mishaps happening with STI, see eg. #333, I need to solve it soon.

@jlaw90
Copy link

jlaw90 commented Mar 19, 2015

@karmi I haven't looked at the source for this gem, but I guess the issue must be that when the module is included it's using the class name to then cache the index, type and other parameters.
The fix would be to change any of these cached variables to be dynamically calculated when they're used.

This is all conjecture though, I don't know if there's anything else funky going on

Edit: thinking about it, additional problems could be caused if adding class methods to the including class. Really it's difficult to debug these sorts of problems, it might be best to write some tests and then go from there.

@karmi
Copy link
Contributor

karmi commented Mar 19, 2015

@jlaw90 Thanks!, I'll have a look at that when I'm back onlilne properly.

@karmi
Copy link
Contributor

karmi commented May 22, 2015

The underlying problem is with the proxied methods. The "practical" solution seems to be include the Elasticsearch::Model module in the child class as well, as outlined in #333 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants