Optimistic locking problem [still]

I did not get any answer last time so I’m posting again:

has anyone an idea why when I try to modify and save a given page, I
always get this traceback? I can not modify any of my site’s pages so
it is a blocking problem :frowning:

I was using svn for 0.5, went to gems for 0.6.{1,2} and it has not
worked since. Using
“rake rails:freeze:edge” does not solve the problem.

Please help

NoMethodError (undefined method +' for nil:NilClass): /vendor/radiant/vendor/rails/activerecord/lib/active_record/locking/optimist ic.rb:64:inupdate_without_callbacks’
/vendor/radiant/vendor/rails/activerecord/lib/active_record/callbacks.rb:267
:in update_without_timestamps' /vendor/radiant/vendor/rails/activerecord/lib/active_record/timestamp.rb:48: inupdate’
/vendor/radiant/vendor/rails/activerecord/lib/active_record/base.rb:1789:in
create_or_update_without_callbacks' /vendor/radiant/vendor/rails/activerecord/lib/active_record/callbacks.rb:242 :increate_or_update’
/vendor/radiant/vendor/rails/activerecord/lib/active_record/base.rb:1545:in
save_without_validation' /vendor/radiant/vendor/rails/activerecord/lib/active_record/validations.rb:7 52:insave_without_transactions’
/vendor/radiant/vendor/rails/activerecord/lib/active_record/transactions.rb:
129:in save' /vendor/radiant/vendor/rails/activerecord/lib/active_record/connection_adapt ers/abstract/database_statements.rb:59:intransaction’
/vendor/radiant/vendor/rails/activerecord/lib/active_record/transactions.rb:
95:in transaction' /vendor/radiant/vendor/rails/activerecord/lib/active_record/transactions.rb: 121:intransaction’
/vendor/radiant/vendor/rails/activerecord/lib/active_record/transactions.rb:
129:in save' /vendor/radiant/app/controllers/admin/page_controller.rb:110:insave’
/vendor/radiant/app/controllers/admin/abstract_model_controller.rb:116:in
h andle_new_or_edit_post' /vendor/radiant/app/controllers/admin/page_controller.rb:25:inedit’
/vendor/radiant/vendor/rails/actionpack/lib/action_controller/base.rb:1095:i
n send' /vendor/radiant/vendor/rails/actionpack/lib/action_controller/base.rb:1095:i nperform_action_without_filters’
/vendor/radiant/vendor/rails/actionpack/lib/action_controller/filters.rb:632
:in call_filter' /vendor/radiant/vendor/rails/actionpack/lib/action_controller/filters.rb:638 :incall_filter’
/vendor/radiant/vendor/rails/actionpack/lib/action_controller/filters.rb:438
:in call' /vendor/radiant/vendor/rails/actionpack/lib/action_controller/filters.rb:637 :incall_filter’
/vendor/radiant/vendor/rails/actionpack/lib/action_controller/filters.rb:619
:in perform_action_without_benchmark' /vendor/radiant/vendor/rails/actionpack/lib/action_controller/benchmarking.r b:66:inperform_action_without_rescue’
/usr/local/lib/ruby/1.8/benchmark.rb:293:in measure' /vendor/radiant/vendor/rails/actionpack/lib/action_controller/benchmarking.r b:66:inperform_action_without_rescue’
/vendor/radiant/vendor/rails/actionpack/lib/action_controller/rescue.rb:83:i
n perform_action' /vendor/radiant/vendor/rails/actionpack/lib/action_controller/base.rb:430:insend’
/vendor/radiant/vendor/rails/actionpack/lib/action_controller/base.rb:430:in
process_without_filters' /vendor/radiant/vendor/rails/actionpack/lib/action_controller/filters.rb:624 :inprocess_without_session_management_support’
/vendor/radiant/vendor/rails/actionpack/lib/action_controller/session_manage
ment.rb:114:in process_without_test' /vendor/radiant/vendor/rails/actionpack/lib/action_controller/test_process.r b:15:inprocess’
/vendor/radiant/vendor/rails/actionpack/lib/action_controller/base.rb:330:in
process' /vendor/radiant/vendor/rails/railties/lib/dispatcher.rb:41:indispatch’
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in
`
process’

I had the same problem. I think there might be something wrong with
the migrations.

If you manually set the lock_version on your database tables to 0
(zero) instead of NULL (which I assume is the problem) you should be ok.

I didn’t see you’re earlier email, otherwise I would have responded.

Does this work for you? I’ve been meaning to look at the code and
submit a patch if necessary but haven’t had time.

-Jim

Ollivier,

I helped Andrew Vonderluft with this same problem recently. First,
make sure you have migrated to the latest version:

rake production db:migrate

Once you have done that, if it still doesn’t work, use script/console
to execute this statement:

[:pages, :snippets, :layouts, :users].each do |table|
ActiveRecord::Base.connection.execute “UPDATE #{table.to_s} SET
lock_version = 0 WHERE lock_version IS NULL”
end

The issue is that some database adapters don’t respond well to the
increment operation when the original value is nil/NULL.

When I get to working on some patches, hopefully later this week, I
will be updating the migration to do this. I’m sorry for your
continued difficulty.

Sean

On 7/5/07, Sean C. [email protected] wrote:

Once you have done that, if it still doesn’t work, use script/console
to execute this statement:

This worked, thanks to Jim and you!

The issue is that some database adapters don’t respond well to the
increment operation when the original value is nil/NULL.

I mentionned a while ago thatI’m using postgresql but didn’t in my
last mail, sorry.

When I get to working on some patches, hopefully later this week, I
will be updating the migration to do this. I’m sorry for your
continued difficulty.

Thanks, I’m back in business :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs