This project is archived and is in readonly mode.
update_attribute should raise exception if invoked on new record
Reported by Sebastian Martinez | March 27th, 2011 @ 02:40 PM
I think that calling #update_attribute on a new record object
should raise an exception, and not have the behavior it has
now.
Right now it does this:
>> p = Post.new
=> #<Post id: nil, title: nil, blog_id: nil, created_at: nil, updated_at: nil, author: nil>
>> p.update_attribute(:title, "My Title")
=> true
>> p
=> #<Post id: 16, title: "My Title", blog_id: nil, created_at: "2011-03-27 13:00:34", updated_at: "2011-03-27 13:00:34", author: nil>
>> p.valid?
=> false
>> p.errors
=> #<ActiveRecord::Errors:0x7f26b3a307b0 @base=#<Post id: 17, title: "My Title", blog_id: nil, created_at: "2011-03-27 13:07:35", updated_at: "2011-03-27 13:07:35", author: nil>, @errors={"blog_id"=>[#<ActiveRecord::Error:0x7f26b3a2e398 @options={}, @type=:blank, @base=#<Post id: 17, title: "p", blog_id: nil, created_at: "2011-03-27 13:07:35", updated_at: "2011-03-27 13:07:35", author: nil>, @message=:blank, @attribute=:blog_id>]}>
Not sure if I would expect it to persist the object, or even
worse, persist an invalid object.
I attach a patch to solve this.
Comments and changes to this ticket
-
Sebastian Martinez March 27th, 2011 @ 03:20 PM
- Assigned user changed from José Valim to Santiago Pastorino
-
Sebastian Martinez March 27th, 2011 @ 03:58 PM
You can also see the commit here: https://github.com/smartinez87/rails/commit/aff3386858de7e2c5339e76...
-
Santiago Pastorino March 28th, 2011 @ 04:25 PM
- State changed from new to wontfix
- Importance changed from to Low
I wouldn't change that on a stable release. People could be trusting this behavior.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>