-
Notifications
You must be signed in to change notification settings - Fork 470
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
Deprecation warning in Rails 5.1 #1165
Comments
Hi André - thanks for reporting this, and for all the excellent detail! This has come up previously - see #1059 and #1085 - but now you've got me second-guessing my thinking (though it's hard to remember how I thought through it all three years ago). It could be that even without changes to the code the original behaviour will continue to work - it's just that the deprecation warnings from Rails aren't super nuanced. Or perhaps I've got it wrong… I'm generally using real-time indices (with TS and Rails 6) these days rather than SQL-backed indices and deltas, though the test suite covers both. I'll try to find some time to put together a test app using deltas and Rails 5.2 to confirm things behave as they should, though not sure when I'll be able to get to that… certainly, if you want to give that a shot, that'd be great! |
First of all, sorry for not having looked at previous issues. I now understand what you mean by deprecation warnings from Rails aren't super nuanced. #1059 enlightened me on that. |
So actually my suggestion as interim solution is actually wrong because Another solution we've found out that seems to work correctly and fixes the deprecation warning is by using |
If you could, that'd be great. Generally I refer to It'd also be good to get a test in place that confirms the correct behaviour with these nested callbacks - which probably means adding a new model to |
@afpr252 Just realised I've left this issue dormant for over a year, sorry! 😅 did you manage to get anywhere with a fix, even if it's not polished up into a PR? |
Hi. We're using the latest version of the thinking sphinx gem (4.4.1) and we recently upgraded to Rails 5.1. Since that upgrade, we've been seeing deprecation warnings in the gem.
Problem
These are the logs we have:
DEPRECATION WARNING: The behavior of
changed?
inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method aftersave
returned (e.g. the opposite of what it returns now). To maintain the current behavior, usesaved_changes?
instead.DEPRECATION WARNING: The behavior of
changed_attributes
inside of after callbacks will be changing in the next version of Rails. The new return value will reflect the behavior of calling the method aftersave
returned (e.g. the opposite of what it returns now). To maintain the current behavior, usesaved_changes.transform_values(&:first)
instead.The code that is calling this deprecated method is on
gems/thinking-sphinx-4.4.1/lib/thinking_sphinx/active_record/callbacks/delta_callbacks.rb#new_or_changed?
The deprecated method is https://apidock.com/rails/ActiveModel/Dirty/changed%3F and the new method that replaces it is https://apidock.com/rails/ActiveRecord/AttributeMethods/Dirty/saved_changes%3F.
Steps to reproduce the issue
The way we reproduced the issue was to create a callback in a model that issues an update which then triggers the thinking sphinx gem.
Then open a rails console and:
Interim solution
As expected, we managed to solve the deprecation warning by monkey-patching the affected class:
However, we would rather to have the fix in upstream.
Do you want me to open a PR with the way we fixed the deprecation warning or is there a better solution given that this new method is not available on Rails prior to 5.1?
The text was updated successfully, but these errors were encountered: