Skip to content

stack level too deep with inheritance_enabled when acessing __elasticsearch__.index_name #729

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

Closed
quorak opened this issue Jul 8, 2017 · 5 comments

Comments

@quorak
Copy link

quorak commented Jul 8, 2017

hey there,

thanks for the great gem.
just followed your docs and came across the folowwing issue when working with inheritance in my rails models.
With the default settings
Ticket::EmailTicket.__elasticsearch__.index_name
return me the correct index name ticket-email_tickets but when Elasticsearch::Model.settings[:inheritance_enabled] = true
I get a

SystemStackError: stack level too deep
from /usr/local/lib/ruby/2.0.0/irb/workspace.rb:86

when accessing the index_name. Obviously also for all methods using the index_name

I have very easy inheritance: Ticket::Ticket is the superclass of Ticket::EmailTicket and also includes the Elasticsearch::Model

I would expect Ticket::EmailTicket.__elasticsearch__.index_name to return ticket-tickets

I'm running on ruby 2.0 and rails 3.2. maybe the modules in my models make this problem.
Happy about any advice.

best

@blevine
Copy link

blevine commented Apr 9, 2018

I am seeing the same problem. I worked around it by adding the below code to my base class, but I don't see why I should need to.

  def self.inherited(subclass)
    index_name(my_index_name)
    document_type(my_doc_type)
    super
  end

@karmi
Copy link
Contributor

karmi commented Apr 25, 2018

@blevine , thanks for posting the workaround.

I've seen including the module again in the child classes to fix it as well. Sorry for the silence here, we're scheduling some effort to focus on the elasticsearch-rails group of gems again soon.

@emilong
Copy link

emilong commented Nov 28, 2018

Another workaround option that's working for me:

class Subclass < Superclass
  __elasticsearch__.index_name = Superclass.__elasticsearch__.index_name
end

Would love to get this resolved with the configuration option though. 😄

@whitelancer
Copy link

whitelancer commented Jan 17, 2019

Just wanted to report that I'm having this same issue. It seems like this code should work, but I think it must be choking on the part where it compares ancestors to self? Not entirely sure.

> Author.__elasticsearch__.send :implicit, :index_name
> "authors"
> NestedAuthor.__elasticsearch__.send :implicit, :index_name
> SystemStackError: stack level too deep
        from (irb):92
def implicit(prop)
            value = nil

            if Elasticsearch::Model.settings[:inheritance_enabled]
              self.ancestors.each do |klass|
                next if klass == self
                break if value = klass.respond_to?(prop) && klass.send(prop)
              end
            end

            value || self.send("default_#{prop}")
end

I haven't had a ton of time to dig into this, but it seems that self here is not correct.

irb(main):095:0> NestedAuthor.__elasticsearch__.ancestors.each {|klass| puts "klass: #{klass}; self: #{self}; ==? #{klass == self}" }
klass: NestedAuthor; self: main; ==? false

And that's what drives this into an infinite loop.

Also, for whatever reason, I can't get the self.inherited workaround functioning for my code.

@estolfo
Copy link
Contributor

estolfo commented Jul 12, 2019

Fixed by #887

@estolfo estolfo closed this as completed Jul 12, 2019
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

6 participants