activerecord-hackery / ransack

Object-based searching.
https://activerecord-hackery.github.io/ransack/
MIT License
5.69k stars 806 forks source link

Rails 7.2 - LoadError: cannot load such file -- polyamorous/activerecord_7.2_ruby_2/join_association (LoadError) #1518

Open EverardB opened 3 months ago

EverardB commented 3 months ago

Upgrade to rails 7.2 and you will get the following message whilst constructing the database...

bin/rails aborted! LoadError: cannot load such file -- polyamorous/activerecord_7.2_ruby_2/join_association (LoadError) Did you mean? polyamorous/activerecord_7.0_ruby_2/join_association polyamorous/activerecord_6.1_ruby_2/join_association polyamorous/activerecord_6.0_ruby_2/join_association

EverardB commented 3 months ago

It seems that this is a fairly important issue to fix... ransack can not be used out-of-the-box in any project from rails 7.1+

scarroll32 commented 1 month ago

https://github.com/activerecord-hackery/ransack/issues/1519#issuecomment-2380644532

PRs welcome

dmytro-strukov commented 1 month ago

@scarroll32 Maybe it will help someone who is also debugging this issue.

Rails 7.2.1 Ruby 3.2.2

x = ArticleCategory.ransack(title_eq: 'Child category')
x.result

It produces the next SELECT "article_categories".* FROM "article_categories" /* loading for pp */ LIMIT $1 [["LIMIT", 11]]

It returns all of the records (should not).

Backtrace of the calls:

ransack-4.2.1/lib/ransack/adapters/active_record/base.rb:15

def ransack(params = {}, options = {})
  Search.new(self, params, options)
end

ransack-4.2.1/lib/ransack/search.rb:43

def result(opts = {})
  @context.evaluate(self, opts)
end

ransack-4.2.1/lib/ransack/adapters/active_record/context.rb:27

def evaluate(search, opts = {})
  viz = Visitor.new
  relation = @object.where(viz.accept(search.base))
   ...
end

ransack-4.2.1/lib/ransack/visitor.rb viz.accept will call visit method here:

def visit(object)
  send(DISPATCH[object.class], object)
end

and this will call visit_Ransack_Nodes_Condition and visit_Ransack_Nodes_Grouping.

The strange behavior that I noticed is that Ransack::Nodes::Condition does not have attributes, it returns an empty array. I read test cases so probably it is not correct behavior, also I run tests locally and they are all green, so the current issue is not covered by them.

dmytro-strukov commented 1 month ago

@EverardB Which versions of Ransack and Rails do you use?

scarroll32 commented 1 month ago

Possible cause https://github.com/activerecord-hackery/ransack/blob/main/lib/polyamorous/polyamorous.rb#L19C1-L20C1

PRs welcome

dmytro-strukov commented 1 month ago

@scarroll32 Could you please provide steps to reproduce the issue?