Skip to content

Fix deprecation warning from Rails 5.1 upgrade (changed_attributes is now attributes_in_database) #758

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

Closed
wants to merge 1 commit into from

Conversation

Geesu
Copy link
Contributor

@Geesu Geesu commented Nov 29, 2017

This PR only changes 2 things to fix the deprecation warning:

  1. changed_attributes changes to attributes_in_database
  2. instance.changes changes to instance. changes_to_save

@Geesu Geesu force-pushed the fix-changed_attributes-warning branch 2 times, most recently from 5f988b2 to 1e0a708 Compare November 29, 2017 14:19
@Geesu Geesu force-pushed the fix-changed_attributes-warning branch from 1e0a708 to caf00ab Compare November 29, 2017 14:25
@karmi karmi closed this in 82b45f5 Dec 4, 2017
karmi added a commit that referenced this pull request Dec 4, 2017
…k with older Rails versions

This patch builds on work in #738 by @jkeam and #758 by @Geesu to prevent deprecation warnings on Rails 5.1
due to changes in the handling of "changed attributes", originally reported by @davedash in #714.

It's primary focus is to restore the compatibility with older Rails versions (so we don't break compatibility
without proper version bump and in a single isolated commit), and to make the naming a bit more descriptive.

First, the condition has been changed to work with the `changes_to_save` and `changes` methods, as opposed
to the original `changed_attributes` / `attributes_in_database` naming. This communicates much more clearly
the intent, and the original usage of `changed_attributes` has been misleading.

Also, the "internal instance variable" which keeps track of the changes has been renamed to `@__changed_model_attributes`,
in order to cleary differentiate it from the `changed_attributes` method name in older ActiveRecord versions.

Closes #758
karmi pushed a commit that referenced this pull request Dec 4, 2017
…o_save` for compatibility with Rails 5.1

Without this patch, the log on Rails 5.1 is full of deprecation warnings like:

    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...

It was first reported in #714.

This patch fixes #758.
karmi added a commit that referenced this pull request Dec 4, 2017
…k with older Rails versions

This patch builds on work in #738 by @jkeam and #758 by @Geesu to prevent deprecation warnings on Rails 5.1
due to changes in the handling of "changed attributes", originally reported by @davedash in #714.

It's primary focus is to restore the compatibility with older Rails versions (so we don't break compatibility
without proper version bump and in a single isolated commit), and to make the naming a bit more descriptive.

First, the condition has been changed to work with the `changes_to_save` and `changes` methods, as opposed
to the original `changed_attributes` / `attributes_in_database` naming. This communicates much more clearly
the intent, and the original usage of `changed_attributes` has been misleading.

Also, the "internal instance variable" which keeps track of the changes has been renamed to `@__changed_model_attributes`,
in order to cleary differentiate it from the `changed_attributes` method name in older ActiveRecord versions.

Closes #758
@karmi
Copy link
Contributor

karmi commented Dec 4, 2017

Hi @Geesu, first of all, many apologies for the delay with processing this patch...

I've merged your patch, and added another one, which restores the functionality for older Rails versions (since I don't want to break the compatibility in an isolated commit, without proper deprecations and version bumps). I've also changed the conditions in 7815039 to use the changes_to_save / changes method names to clearly indicate the intent: my original code using the changed_attributes was very confusing.

Can you please evaluate this version? I've also pushed it to the 5.x branch, and released it as 5.0.2 on Rubygems.

@Geesu Geesu deleted the fix-changed_attributes-warning branch December 4, 2017 18:00
jordan-brough pushed a commit to Lostmyname/elasticsearch-rails that referenced this pull request Jan 9, 2018
…o_save` for compatibility with Rails 5.1

Without this patch, the log on Rails 5.1 is full of deprecation warnings like:

    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...

It was first reported in elastic#714.

This patch fixes elastic#758.
jordan-brough pushed a commit to Lostmyname/elasticsearch-rails that referenced this pull request Jan 9, 2018
…k with older Rails versions

This patch builds on work in elastic#738 by @jkeam and elastic#758 by @Geesu to prevent deprecation warnings on Rails 5.1
due to changes in the handling of "changed attributes", originally reported by @davedash in elastic#714.

It's primary focus is to restore the compatibility with older Rails versions (so we don't break compatibility
without proper version bump and in a single isolated commit), and to make the naming a bit more descriptive.

First, the condition has been changed to work with the `changes_to_save` and `changes` methods, as opposed
to the original `changed_attributes` / `attributes_in_database` naming. This communicates much more clearly
the intent, and the original usage of `changed_attributes` has been misleading.

Also, the "internal instance variable" which keeps track of the changes has been renamed to `@__changed_model_attributes`,
in order to cleary differentiate it from the `changed_attributes` method name in older ActiveRecord versions.

Closes elastic#758
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