Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

#[] and #[]= are no longer interchangeable with #read_attribute and #write_attribute #4408

Merged
merged 3 commits into from Jan 11, 2012

Conversation

Projects
None yet
5 participants
Contributor

tomstuart commented Jan 11, 2012

21eadc1 forced ActiveRecord::Base#[] and #[]= to use the default implementations of #read_attribute and #write_attribute respectively; if one of the latter methods is redefined, or wrapped with alias_method_chain, its alias will retain the default behaviour.

I don't think this change in semantics was intentional, so I've added tests for the expected behaviour and reverted 21eadc1 to make them pass.

Owner

pixeltrix commented Jan 11, 2012

This gets a +1 from me since 21eadc1 will break any gems/plugins that hook into read/write_attribute via alias_method_chain or even if they include a module into AR::Base and call super.

spastorino added a commit that referenced this pull request Jan 11, 2012

Merge pull request #4408 from tomstuart/read-and-write-attribute-aliases
#[] and #[]= are no longer interchangeable with #read_attribute and #write_attribute

@spastorino spastorino merged commit 3f8f96e into rails:master Jan 11, 2012

spastorino added a commit that referenced this pull request Jan 11, 2012

Merge pull request #4408 from tomstuart/read-and-write-attribute-aliases
#[] and #[]= are no longer interchangeable with #read_attribute and #write_attribute
Contributor

tomstuart commented Jan 11, 2012

Would you also accept backports to 3-1-stable and 3-2-stable?

Owner

spastorino commented Jan 11, 2012

@tomstuart I've backported it to 3-2-stable, please provide a pull request for 3-1-stable, thanks!!!

Contributor

tomstuart commented Jan 12, 2012

Done: #4418.

Huh, why hasn't this worked?

Owner

fxn replied Jan 12, 2012

It is good to add a separate paragraph in the commit message with a rationale for the archives.

Owner

spastorino commented Jan 12, 2012

@tomstuart merged

@fsvehla what didn't work?

fsvehla commented Jan 12, 2012

It was reverted in dcebe7f

Owner

spastorino commented Jan 12, 2012

@fsvehla Ahhh, read the description of this pull request :)

fsvehla commented Jan 12, 2012

@Spar Oh, yes, I get it now, thanks. Ruby does alias the method at the time when alias_method is executed, which is cool, and non-obvious.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment