Hi there,
Here's a bug I have half tracked down. It looks like the model isn't keeping track of the original primary key properly, so the update fails.
Here's some code to reproduce it:
require 'rubygems' require 'sequel' DB = Sequel.connect 'postgres://localhost/foobar' DB.create_table(:items) { String :name, :primary_key => true } class Item < Sequel::Model end i = Item.new i.name = 'hello' i.save i.name = 'there' i.save
Sequel::NoExistingObject: Attempt to update object did not result in a single row modification (SQL: UPDATE "items" SET "name" = 'there' WHERE ("name" = 'there'))
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:1235:in _update'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:1203:in
_save'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:961:in block (2 levels) in save'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:1261:in
block in checked_transaction'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/database/query.rb:223:in _transaction'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/database/query.rb:209:in
block in transaction'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/connection_pool/threaded.rb:84:in hold'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/database/connecting.rb:224:in
synchronize'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/database/query.rb:207:in transaction'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:1261:in
checked_transaction'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:961:in block in save'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:1249:in
checked_save_failure'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:961:in save'
from (irb):12
from /Users/zaius/.rvm/rubies/ruby-1.9.2-rc2/bin/irb:17:in
<main>'
I also am getting this error, which I assume is related:
>> Item.create :name => 'blah'
Sequel::Error: method name= doesn't exist or access is restricted to it
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:1292:in block in set_restricted'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:1287:in
each'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:1287:in set_restricted'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:985:in
set'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:674:in initialize'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:123:in
new'
from /Users/zaius/.rvm/gems/ruby-1.9.2-rc2/gems/sequel-3.14.0/lib/sequel/model/base.rb:123:in create'
from (irb):13
from /Users/zaius/.rvm/rubies/ruby-1.9.2-rc2/bin/irb:17:in
<main>'
I'm on pg version 0.9.0, sequel 3.14.0, ruby 1.9.2 Let me know if you need any more info.
david
Comment #1
Posted on Aug 28, 2010 by Swift RhinoAh, my bad on the second error. That can be fixed by adding 'unrestrict_primary_key' to the model. The first error still stands though.
Comment #2
Posted on Aug 28, 2010 by Happy BearThis behavior is by design. You need to use the update_primary_key plugin if you want to be able to modify and save primary keys (http://sequel.rubyforge.org/rdoc-plugins/classes/Sequel/Plugins/UpdatePrimaryKey.html).
Comment #3
Posted on Aug 28, 2010 by Swift RhinoMakes sense. Would be good to get a better error message in there though. This has taken me a while to track down. Thanks for the quick reply!
david
Status: WontFix