-
-
Notifications
You must be signed in to change notification settings - Fork 357
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
Silence deprecation warning in rails 6 [redo] #384
Silence deprecation warning in rails 6 [redo] #384
Conversation
Thanks for re-opening! I went through the links to prior issues @brendon listed here: #363 (comment) It does look like existing tests should cover this change However I wasn't able to get those tests to fail, for example by changing the
So I'm not sure if I'm doing something wrong or those tests aren't doing what they think they are? Maybe someone else could verify. I was testing with |
Great question @sudara. I tried a bunch of scenarios:
I guess the question is, do we need the Maybe there aren't enough tests to capture what we'd be missing out on by excluding |
Oh, and I'm getting these results by running just |
The main goal of the selective unscoping was to preserve any special |
Hey @brendon any update on this? I keep coming back and checking this PR from time to time to see if it's been merged. Is there anything I can do to help? can you clarify exactly what the issue/danger with this PR is? Is there a test for whatever the issue might be (that'd help me dig in to try and help ensure we mitigate whatever it might be)? |
1. Default is to get latest activerecord which is now 6 and this doesn't work with sqlite 1.3, so we need to change the version requested by the default Gemfile to 1.4. 2. Activerecord 4.2 and 5.0 don't work with sqlite 1.4 so we need to pin the sqlite version for those gemfiles to 1.3 now that the default is 1.4. We also regenerate the gemfiles these changes would create.
FWIW: I locally added the rail 6.1.0.rc1 gem to a new appraisal and ran the tests under various versions of the code to see what would happen. The dev warning explicitly says rails 6.1 will change the behaviour so I hoped this would tell us something. Unfortunately:
Note: I couldn't get the appraisal for 4.2 to install locally - suspect I need a specific old ruby + pg for compiling - I suspect something would break in at least scenario 3 for 4.2. If we're not confident that replacing There are two scenarios that seem likely to me:
I can't really say that I feel super confident either way TBH. My main concern was just getting rid of the dep warning from my console, and it seems it will go away when rails 6.1 is released and we upgrade our app so ... 🤷 |
Thanks @h-lame, that's super interesting. I had a suspicion that it may be a false warning. There is some more discussion on this here: rails/rails#38881 Just to clarify my understanding: your code is calling |
What about: acts_as_list_class.default_scoped.unscope(:select, :where) ? |
It's baffling that I didn't think to try this in the first place! Thanks for suggesting. If it does that then rails 6-1, 6-0, 5-2, and 5-0 appraisals all pass. So maybe that's the solution (again, not entirely sure that introducing the I'll push up a commit that does that so we can see what 4-2 does 'cos I can't get that running locally. |
Yes - turns out it is this situation. Relevant bits of the callstack:
That rails issue isn't exactly conclusive, but it feels like it might not be what anyone expected. |
083fd5b
to
279c87b
Compare
Haha! It only occurred to me after reading through what |
279c87b
to
013617d
Compare
Looks like travis and the appraisals are happy with those changes. Always use |
Sounds good to me @h-lame, how far back goes |
Man Travis is quite slow at running tests now! I suppose it's free though. Ping me back if you notice it's done and green :) |
@brendon looks like it went fully green. So seems we can use |
I'm happy with that. Glad to finally have figured this one out :D |
I don't think there's a version string to make this not need to be manually updated when 6.1 comes out of pre-release though.
In rails 6 we get the following deprecation warning: DEPRECATION WARNING: Class level methods will no longer inherit scoping from `create` in Rails 6.1. To continue using the scoped relation, pass it into the block directly. To instead access the full set of models, as Rails 6.1 will, use `<model name>.default_scoped`. (called from acts_as_list_list at /path/to/acts_as_list/lib/acts_as_list/active_record/acts/list.rb:229) when we call `find_or_create_by` on a model with `acts_as_list`. To get rid of this deprecation warning, we can introduce a call to `default_scoped` before the existing call to `unscope(:select, :where)`. This method has been available since rails 4.x so we don't need to do a version check for this and it should work across all rails versions.
bbc1e9f
to
a3d6193
Compare
Ok, sorry for leaving this for a few days @brendon, but I've smooshed those WIP commits down and left it as the two appraisals update commits and one commit talking about using |
Perfect! Thanks for that @h-lame, great to get this one out of the gate! |
@brendon is there a timeline for when this will be released as a gem? |
Merry Christmas @fschwahn :) 🎄 |
awesome, thanks! |
In rails 6 we get the following deprecation warning:
when we call
find_or_create_by
on a model withacts_as_list
. To getrid of this deprecation warning, we need
default_scoped.unscoped
instead of the restricted
unscope(:select, :where)
.In the first commit I've also tweaked the Gemfile and Appraisals files to work out of the box now that rails 6 is available and it doesn't work with sqlite 1.3.
Note - this is a redo of #363 because I foolishly deleted the source repo and had to recreate it to update the PR. It also incorporates comments from that PR discussion:
default_scoped
)default_scoped.unscoped
)Sorry for the noise. I'll close the other one.