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

Be more surgical about unscoping #265

Merged
merged 2 commits into from
Apr 4, 2017
Merged

Conversation

brendon
Copy link
Owner

@brendon brendon commented Mar 30, 2017

We now only remove the where scopes, and use reorder where
necessary to ensure our ordering is paramount.

Rails 3.2 compatibility is maintained via the except method instead
of unscope.

Fixes #263

We now only remove the `where` scopes, and use `reorder` where
necessary to ensure our ordering is paramount.

Rails 3.2 compatibility is maintained via the `except` method instead
of `unscope`.
@brendon
Copy link
Owner Author

brendon commented Mar 30, 2017

Bummer. Looks like Rails 3.2 isn't working yet. I'll keep going.

@brendon brendon requested review from swanandp and fabn April 1, 2017 07:02
@brendon
Copy link
Owner Author

brendon commented Apr 1, 2017

Sadly, in Rails 3.2 except(:where).where() doesn't work as expected and still leaves in the default_scope.

I was close to dropping 3.2 support but realised we could still continue, but just fork the code (as we were already doing anyway) for 3.2 so that it used our existing model of unscoped do since this is just a refinement of the functionality.

All tests should pass (they do locally) so are you happy for me to merge this change on a minor version? The only functionality change might be that people are incorrectly relying on the unscoping but I doubt it.

@swanandp
Copy link
Contributor

swanandp commented Apr 3, 2017

Proposal: For all the 3.2 and backwards compatibility hacks fixes, we should add a mixin, and override there. This will reduce branching, and put all the code in one place.

Copy link
Contributor

@swanandp swanandp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments, but otherwise seems good. I haven't had a chance to test this on a 3.2 app though.

@@ -48,6 +48,7 @@ def teardown_db

require "shared"

# require 'logger'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an oversight? We could just remove it otherwise.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason logger wasn't being loaded when I was running the tests locally with Appraisal and the Rails 3.2 gemset. Sometimes it's handy to be able to see the SQL logs when debugging the tests so I've left this here commented out to save searching for the solution again in the future.

@brendon
Copy link
Owner Author

brendon commented Apr 3, 2017

RE the Mixin, that sounds like a good idea. I'll have a go at that now.

@brendon
Copy link
Owner Author

brendon commented Apr 3, 2017

Actually, following this up. There really isn't anywhere else where we're checking the rails version for Rails 3.2. Mostly it's checking for things like > 5. The only other Rails 3 check is when dealing with detecting destroy via a parent (that we added recently) and we're just skipping that functionality for Rails 3.

I'm at a loss as to where to start given some of this code is within the meta-code 'definers'.

I'm happy to work on it, but need a bit more assistance with how to structure it.

Otherwise, we can commit this as is, then draw a line in the sand and the next time a code branch is required for Rails 3.2 we'll just drop support. What do you think?

@swanandp
Copy link
Contributor

swanandp commented Apr 4, 2017 via email

@brendon brendon merged commit 47f4111 into master Apr 4, 2017
@brendon brendon deleted the unscope(where)-vs-unscoped branch April 4, 2017 03:22
brendon added a commit to brendon/ancestry that referenced this pull request Jul 3, 2017
Related to: brendon/acts_as_list#265

I’ve been running into deadlocks in my app. In the past I’ve identified
these being caused by `acts_as_list` being too greedy in its unscoping
(removing default order scopes, and thus creating situations where the
table is searched from opposite ends resulting in a deadlock).

Ancestry seems to be doing the same thing. I’ve made a modification
that ensures we only remove the `:where` scope, leaving other scopes
(like `:order`) intact. The tests still pass (locally). I’ve added in a
workaround for Rails 3.2 that doesn’t support this functionality.
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

Successfully merging this pull request may close these issues.

2 participants