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
Fix inconsistency with changed attributes when overriding AR attribute reader #28661
Fix inconsistency with changed attributes when overriding AR attribute reader #28661
Conversation
0c735f0
to
071448e
Compare
Please review. |
071448e
to
7e28507
Compare
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
7e28507
to
b5eb321
Compare
Failed tests aren't related to changes |
Thanks for restart tests! Any thoughts about this PR? |
For posterity, also note follow-up in #28760 |
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.
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.
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.
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.
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.
Fixes #28660.