-
Notifications
You must be signed in to change notification settings - Fork 363
Deprecate writing to Base#attributes
#463
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
Merged
guilleiguaran
merged 1 commit into
rails:main
from
seanpdoyle:deprecate-attributes-write
Nov 19, 2025
+59
−4
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| module ActiveResource | ||
| class AttributeSet < DelegateClass(Hash) # :nodoc: | ||
| MESSAGE = "Writing to the attributes hash is deprecated. Set attributes directly on the instance instead." | ||
|
|
||
| deprecate(**[ :[]=, :store, :update, :merge! ].index_with(MESSAGE), | ||
| deprecator: ActiveResource.deprecator) | ||
|
|
||
| delegate :is_a?, to: :__getobj__ | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This really sucks. I don't think it is worth a deprecation if we are going to start using
sendandinstance_variable_setinside the framework code.# :nodoc:should be enough. I'll revert itUh oh!
There was an error while loading. Please reload this page.
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.
@rafaelfranca that feedback is valid. Deprecating assignment is mainly for the sake of #410.
If #410 is not viable, this isn't worthwhile.
If #410 is viable, this might be worth reconsidering. Rather than
send :instance_variable_set, would wrapping this call to#attributes=in a silence block be a good enough temporary solution so that the deprecation could be released ahead of #410 being released?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.
attributes=was never public, so I'm not sure why we need to deprecate it in order to addActiveModel::Attributes.ActiveModel::Attributesdon't defineattributes=, onlyattributes.Also, now
attributes=is just defaulting to themethod_missingbehavior since it is protected. So I will deprecate it there.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.
You're right -- the
attr_accessor :attributeswas marked as# :nodoc:https://github.com/rails/activeresource/blob/v6.1.4/lib/active_resource/base.rb#L1184
The idea to deprecate the accessor came from it being Ruby-level
public. Since it's omitted from the public documentation, I defer to you on whether or not a deprecation cycle is necessary. Skipping the deprecation cycle would simplify things a lot.