Elasticsearch-rails: `changed_attributes` is deprecated in Rails 5.1

Created on 18 May 2017  路  7Comments  路  Source: elastic/elasticsearch-rails

changed_attributes is deprecated in favor of saved_attributes.

When I updated my project to Rails 5.1 I started seeing this:

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 after `save` returned (e.g. the opposite of what it returns now). To maintain the current behavior, use `saved_changes.transform_values(&:first)` instead. (called from update_funding_caches at...

The stack-trace included a reference to this:

https://github.com/elastic/elasticsearch-rails/blob/2.x/elasticsearch-model/lib/elasticsearch/model/proxy.rb#L65

I'm not sure how to cleanly resolve this without modifying elasticsearch-model.

Most helpful comment

Hi all, and especially @davedash, please accept my apologies for not solving this problem sooner.

I've spent some time with @jkeam's and @Geesu's patches, and I think we have a solution in 7815039 which solves the problem with Rails 5.1 and keeps the compatibility with older Rails versions.

I'll close this issue for now, if it's OK, can you please re-open or open a new one if the problem persists?

All 7 comments

Ya, you can see the approach I took here:

https://github.com/jkeam/elasticsearch-rails/commit/e3a764b28a48c197d0167cd17bf2e4588434bddf

I haven't tested it enough to see the full ramifications of the changes (which is why I haven't opened a PR) but I based my changes off of the great descriptions found here:

https://github.com/rails/rails/pull/25337#issuecomment-225166796

From my point of view @jkeam's code looks fine. @jkeam, could you open a pr so this can be discussed with the maintainers of this gem?

Good call. Opening a PR now.

Hi all, and especially @davedash, please accept my apologies for not solving this problem sooner.

I've spent some time with @jkeam's and @Geesu's patches, and I think we have a solution in 7815039 which solves the problem with Rails 5.1 and keeps the compatibility with older Rails versions.

I'll close this issue for now, if it's OK, can you please re-open or open a new one if the problem persists?

@karmi Thanks for fixing this. We ended up running into a lot of little issues in general (not just ES related) when trying to upgrade to 5.1 for our project, that we just settled for 5.0.x. But I'm glad that this won't be a blocker.

Agreed, thanks so much @karmi and everyone else that helped with this issue.

Thanks for the info, @davedash, and good luck with the upgrade!

Was this page helpful?
0 / 5 - 0 ratings