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

Remove circular join references in join_dependency #25702

Merged
merged 1 commit into from Jul 28, 2016

Conversation

@k0kubun
Copy link
Contributor

@k0kubun k0kubun commented Jul 5, 2016

Summary

This patch fixes stack level too deep error introduced in #18109.

Other Information

See #25653 for detail.

@rails-bot
Copy link

@rails-bot rails-bot commented Jul 5, 2016

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@kamipo
kamipo reviewed Jul 5, 2016
View changes
activerecord/lib/active_record/associations/join_dependency/join_association.rb Outdated
@@ -56,7 +56,7 @@ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scop

klass_scope =
if klass.current_scope
klass.current_scope.clone
remove_circular_references(klass.current_scope.clone)

This comment has been minimized.

@kamipo

kamipo Jul 5, 2016
Member

Join associations are a part of a join root. This means that join parts should prevent to construct another join root.

--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -56,7 +56,9 @@ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scop

             klass_scope =
               if klass.current_scope
-                klass.current_scope.clone
+                klass.current_scope.clone.tap { |scope|
+                  scope.joins_values = []
+                }
               else
                 relation = ActiveRecord::Relation.create(
                   klass,

This comment has been minimized.

@k0kubun

k0kubun Jul 5, 2016
Author Contributor

Oh, so I guess you mean joins_values are already used to build current join dependencies in this part and joins_values should not be used here. I think that's true. Fixed 487be17.

@k0kubun k0kubun force-pushed the k0kubun:joins-circular-reference branch Jul 5, 2016
@sgrif
sgrif reviewed Jul 27, 2016
View changes
activerecord/test/cases/scoping/relation_scoping_test.rb Outdated
@@ -228,6 +228,14 @@ def test_current_scope_does_not_pollute_sibling_subclasses
assert SpecialComment.all.any?
end
end

def test_circular_joins_with_current_scope_does_not_crash
assert_nothing_raised do

This comment has been minimized.

@sgrif

sgrif Jul 27, 2016
Contributor

Can you change the test to demonstrate the expected behavior instead of just assert_nothing_raised?

This comment has been minimized.

@k0kubun

k0kubun Jul 27, 2016
Author Contributor

Like this? 28c2997

@k0kubun k0kubun force-pushed the k0kubun:joins-circular-reference branch 2 times, most recently to 28c2997 Jul 27, 2016
@sgrif sgrif merged commit a64d983 into rails:master Jul 28, 2016
2 checks passed
2 checks passed
codeclimate Code Climate didn't find any new or fixed issues.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@k0kubun k0kubun deleted the k0kubun:joins-circular-reference branch Jul 28, 2016
kamipo added a commit to kamipo/rails that referenced this pull request May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.