Fix inconsistency with changed attributes when overriding AR attribute reader #28661
Conversation
Please review. |
activerecord/test/cases/dirty_test.rb
Outdated
@@ -671,6 +671,25 @@ def test_datetime_attribute_doesnt_change_if_zone_is_modified_in_string | |||
assert binary.changed? | |||
end | |||
|
|||
test "changes is correct if override attribute accessor" do |
avgerin0s
Apr 11, 2017
Contributor
I'd rewrite this example message as well as the commit message to reference reader
or getter
explicitly, since writter/setter
overrides do not affect Dirty hash negatively.
I'd rewrite this example message as well as the commit message to reference reader
or getter
explicitly, since writter/setter
overrides do not affect Dirty hash negatively.
bogdanvlviv
Apr 12, 2017
Author
Contributor
Thank you
Thank you
avgerin0s
Apr 13, 2017
Contributor
:)
:)
b5eb321
Failed tests aren't related to changes |
Thanks for restart tests! Any thoughts about this PR? |
For posterity, also note follow-up in #28760 |
shioyama
added a commit
to shioyama/mobility
that referenced
this pull request
Nov 30, 2017
This is required due to a fix in AR 5.2: rails/rails#28661 Previously, `__send__` was used to fetch the value of the attribute before changes, which worked fine with locale accessors like `title_en`. However, with the fix above, `@attributes` is now used, which does not contain translated attributes (let alone locale accessors). Since in general, locale accessors are an open-ended set, we can't treat them the way normal attributes are treated, so we resort to overriding `_read_attribute` to check if the attribute that has changed is one that Mobility changed, and if so use `__send__`. This fixes the issue, although overriding a private method is not ideal.
shioyama
added a commit
to shioyama/mobility
that referenced
this pull request
Nov 30, 2017
This is required due to a fix in AR 5.2: rails/rails#28661 Previously, `__send__` was used to fetch the value of the attribute before changes, which worked fine with locale accessors like `title_en`. However, with the fix above, `@attributes` is now used, which does not contain translated attributes (let alone locale accessors). Since in general, locale accessors are an open-ended set, we can't treat them the way normal attributes are treated, so we resort to overriding `_read_attribute` to check if the attribute that has changed is one that Mobility changed, and if so use `__send__`. This fixes the issue, although overriding a private method is not ideal.
shioyama
added a commit
to shioyama/mobility
that referenced
this pull request
Nov 30, 2017
This is required due to a fix in AR 5.2: rails/rails#28661 Previously, `__send__` was used to fetch the value of the attribute before changes, which worked fine with locale accessors like `title_en`. However, with the fix above, `@attributes` is now used, which does not contain translated attributes (let alone locale accessors). Since in general, locale accessors are an open-ended set, we can't treat them the way normal attributes are treated, so we resort to overriding `_read_attribute` to check if the attribute that has changed is one that Mobility changed, and if so use `__send__`. This fixes the issue, although overriding a private method is not ideal.
shioyama
added a commit
to shioyama/mobility
that referenced
this pull request
Nov 30, 2017
This is required due to a fix in AR 5.2: rails/rails#28661 Previously, `__send__` was used to fetch the value of the attribute before changes, which worked fine with locale accessors like `title_en`. However, with the fix above, `@attributes` is now used, which does not contain translated attributes (let alone locale accessors). Since in general, locale accessors are an open-ended set, we can't treat them the way normal attributes are treated, so we resort to overriding `_read_attribute` to check if the attribute that has changed is one that Mobility changed, and if so use `__send__`. This fixes the issue, although overriding a private method is not ideal.
shioyama
added a commit
to shioyama/mobility
that referenced
this pull request
Nov 30, 2017
This is required due to a fix in AR 5.2: rails/rails#28661 Previously, `__send__` was used to fetch the value of the attribute before changes, which worked fine with locale accessors like `title_en`. However, with the fix above, `@attributes` is now used, which does not contain translated attributes (let alone locale accessors). Since in general, locale accessors are an open-ended set, we can't treat them the way normal attributes are treated, so we resort to overriding `_read_attribute` to check if the attribute that has changed is one that Mobility changed, and if so use `__send__`. This fixes the issue, although overriding a private method is not ideal.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Fixes #28660.