Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

update_attribute should raise exception if invoked on new record

#6630

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.

Reported by Sebastian Martinez · March 27th, 2011 @ 02:40 PM

State: wontfix
Milestone: none
Assigned to: Santiago Pastorino Santiago Pastorino
Importance: Low

Activity

  1. Sebastian Martinez
    Sebastian Martinez
    • Assigned user changed from José Valim to Santiago Pastorino

    March 27th, 2011 @ 03:20 PM

  2. Sebastian Martinez
  3. Santiago Pastorino
    Santiago Pastorino
    • 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.

    March 28th, 2011 @ 04:25 PM