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 fix-dirty-attributes-if-override-attr_accessor branch 2 times, most recently from 0c735f0 to 071448e Compare April 5, 2017 05:43
@bogdanvlviv
Copy link
Contributor Author

Please review.

@bogdanvlviv bogdanvlviv force-pushed the fix-dirty-attributes-if-override-attr_accessor branch from 071448e to 7e28507 Compare April 8, 2017 20:25
@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

@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 fix-dirty-attributes-if-override-attr_accessor branch from 7e28507 to b5eb321 Compare April 12, 2017 05:06
@bogdanvlviv
Copy link
Contributor Author

bogdanvlviv commented Apr 12, 2017

Failed tests aren't related to changes

@bogdanvlviv
Copy link
Contributor Author

Thanks for restart tests! Any thoughts about this PR?

@tenderlove tenderlove merged commit e447c8c into rails:master Apr 14, 2017
@bogdanvlviv bogdanvlviv deleted the fix-dirty-attributes-if-override-attr_accessor branch April 14, 2017 17:31
@matthewd
Copy link
Member

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
Development

Successfully merging this pull request may close these issues.

None yet

5 participants