Skip to content
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

Conversation

@bogdanvlviv
Copy link
Contributor

@bogdanvlviv bogdanvlviv commented Apr 4, 2017

Fixes #28660.

@bogdanvlviv bogdanvlviv changed the title Fix dirty attributes if override attribute accessor Fix dirty attributes if override AR attribute accessor Apr 4, 2017
@bogdanvlviv bogdanvlviv changed the title Fix dirty attributes if override AR attribute accessor Fix inconsistency with changed attributes when overriding AR attribute accessor Apr 4, 2017
@bogdanvlviv bogdanvlviv force-pushed the bogdanvlviv:fix-dirty-attributes-if-override-attr_accessor branch 2 times, most recently Apr 4, 2017
@bogdanvlviv
Copy link
Contributor Author

@bogdanvlviv bogdanvlviv commented Apr 7, 2017

Please review.

@bogdanvlviv bogdanvlviv force-pushed the bogdanvlviv:fix-dirty-attributes-if-override-attr_accessor branch Apr 8, 2017
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

This comment has been minimized.

@avgerin0s

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.

This comment has been minimized.

@bogdanvlviv

bogdanvlviv Apr 12, 2017
Author Contributor

Thank you

This comment has been minimized.

@avgerin0s

avgerin0s Apr 13, 2017
Contributor

:)

@bogdanvlviv bogdanvlviv changed the title Fix inconsistency with changed attributes when overriding AR attribute accessor Fix inconsistency with changed attributes when overriding AR attribute reader Apr 12, 2017
@bogdanvlviv bogdanvlviv force-pushed the bogdanvlviv:fix-dirty-attributes-if-override-attr_accessor branch to b5eb321 Apr 12, 2017
@bogdanvlviv
Copy link
Contributor Author

@bogdanvlviv bogdanvlviv commented Apr 12, 2017

Failed tests aren't related to changes

@bogdanvlviv
Copy link
Contributor Author

@bogdanvlviv bogdanvlviv commented Apr 13, 2017

Thanks for restart tests! Any thoughts about this PR?

@tenderlove tenderlove merged commit e447c8c into rails:master Apr 14, 2017
2 checks passed
2 checks passed
codeclimate no new or fixed issues
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@bogdanvlviv bogdanvlviv deleted the bogdanvlviv:fix-dirty-attributes-if-override-attr_accessor branch Apr 14, 2017
@matthewd
Copy link
Member

@matthewd matthewd commented Apr 14, 2017

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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.