Displaying 20 results from an estimated 10000 matches similar to: "Optimistic locking and update_attributes: not working?"
2006 May 09
7
When to use optimistic locking?
Hi All,
I''m having some trouble deciding when and how to implement optimistic
locking.
Let''s say I have a multiuser Rails app, and let''s say it stores,
among other things "vital" customer information.
The standard methods created by the Rails generate scaffold script
look like this:
def edit
@customer = Customer.find(params[:id])
end
2008 Feb 08
2
update_Attributes stale Object error
Hi,
IN one of my unit tests I get an ActiveRecord::StaleObjectError:
Attempted to update a stale object
object.save!
in object I have apart from other stuff an after_save method, which
calls
object.assosication.update_attributes(...)
If I remove that line from my code my tests succeeds.
Unfortunetly, I do not understand why an update_attributes call can
generate an StaleObjectError.
Maybe
2009 Aug 10
1
[PATCH server] Fixed db-omatic so it doesn't die due to an unhandled ActiveRecord::StaleObjectError exception.
The error is caused by the save! method updating an object that another
thread (most likely in taskomatic) already updated.
In the case of this race condition, we retry saving. However, a proper fix
would involve fixing the locking.
---
src/db-omatic/db_omatic.rb | 23 ++++++++++++++++++++---
1 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/src/db-omatic/db_omatic.rb
2006 Apr 11
1
Implementing Optimistic Offline Lock - How ?
I understand that ActiveRecord supports the "optimistic offline
lock"-pattern through magic fields (created_at, updated_at). However, a
scaffolded CRUD-Controller doesn''t generate the necessary code to
support this feature (the model state gets lost between two action
calls).
What is the best practice to prevent users from overwriting objects with
outdated data ?
--
2013 Feb 25
7
Optimistic Locking Enhancements: Gem or Core?
I''m working on an app that makes use of rails'' optimistic locking feature
and seeing some possibilities for improvements. It seems a bit tedious to
have to add :lock_version to forms wherever the model is used. You also
have to "hack" around rails'' UJS feature to add it as a URL parameter when
using remote: true, method: [:put, :patch, :post, :delete].
2008 Oct 21
1
How to force a lock_version increment
Hi everyone,
I have a order with order_lines use case. On changing the lines, I
want to be sure no one else changed the order. So I use lock_version
on the order. This works fine if something is changed on the order
record.
But now i have the situation that I delete, alter and add order lines
without changing the order record itself. I have to check and
increment the order#lock_version however
2006 Jul 06
4
update_all Not Incrementing lock_version
Shouldn''t update_all be updating lock_version? As you can see from my
console session below, it is upating the record (changed running
attribute to true and returned 1 to show 1 recored was updated). But it
did not increment lock_version. And optimistic locking is working
correctly otherwise. As you can see below, lock version = 562 before
and after the update_all call but it is
2006 May 17
0
acts_as_versioned with lock_version bug?
Hello.
The acts_as_versioned plugin works fine ... till the adjunction
of optimistic locking via the lock_version table column.
Here is the problem description:
Without optimistic locking things are fine:
# ++++ The table creation migration ++++
% cat db/migrate/001_create_tables.rb
class CreateTables < ActiveRecord::Migration
def self.up
create_table :softwares,
2010 Jun 08
1
[PATCH] Fix optimistic locking during vm migration
Signed-off-by: Loiseleur Michel <mloiseleur at linagora.com>
---
src/db-omatic/db_omatic.rb | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/src/db-omatic/db_omatic.rb b/src/db-omatic/db_omatic.rb
index da11bfa..79f29d2 100755
--- a/src/db-omatic/db_omatic.rb
+++ b/src/db-omatic/db_omatic.rb
@@ -195,6 +195,9 @@ class DbOmatic < Qmf::ConsoleHandler
end
2006 Jan 04
2
Rename lock_version field?
Hi,
Is there a way to tell Rails that the magic field name for optimistic
database locking is not lock_version? I have a legacy database where the
optimistic locking field is named "version".
Thanks,
Phil
--
Posted via http://www.ruby-forum.com/.
2013 Feb 26
0
Feedback Needed: Optimistic Locking Destroy Bug
Need feedback on what I think is a bug in AR related to destroying models
with optimistic locking.
Please check this PR for more
information: https://github.com/rails/rails/pull/9448
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
2006 Feb 23
7
Session Based Record Locking - Solutions?
All,
I''ve written a simple job/opportunity tracking database app via RoR.
I have about 10 internal users.
Sometimes 2 people will want to update the same record at more or less
the same time and they collide.
In particular user 1 may edit a record, then get distracted, and
finally an hour later they click save.
During that hour user 2 may have pulled up the record, edited it, and
2010 Sep 22
0
ActiveRecord#touch behaviour in Rails 3
In Rails 2.x, calling touch on an ActiveRecord model would update the
''lock_version'' on the model, if it were present.
It would produce something like this in SQL:
UPDATE `foo` SET `updated_at` = ''2010-07-23 10:44:19'', `lock_version''
= 2 WHERE ''lock_version'' = 1
This would ensure that your optimistic locking policy will be followed
2007 Jul 31
0
Force an object to previous state, when using lock_version
If I have an exception while trying to save an object, how can I tell
Rails that it''s not saved yet?
The object has a lock_version (used for optimistic locking). This is
what I do:
ins = MyClass.new( arguments )
begin
transaction do
ins.save!
bunch_of_other_stuff()
end
rescue
ins.save! # problem here!
end
The object''s save() sets the internal object state in a saved
2009 Aug 10
0
[PATCH server] Fixed db-omatic so it doesn't die due to unhandled exceptions related to saving db objects in update_host_state and update_domain_state.
The underlying issue has to do with optimistic locking for active record,
and contention between db-omatic and task-omatic. That still needs to be
fixed, especially since contention issues might get worse when the two
daemons are made multithreaded.
---
src/db-omatic/db_omatic.rb | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)
diff --git
2009 Feb 03
1
update_attributes! does not update nested model
Hi!
I have updated my app to rails 2.3. I have form that has few nested
models and I am happy that I can just write
accepts_nested_attributes_for :tasks, :allow_destroy => true, but
update_attributes! does not update my nested model. I have tried
update_attributes, and it works. Any ideas?
Few lines from log:
update_attributes:
SQL (0.1ms) BEGIN
Education Update (0.3ms) UPDATE
2008 Aug 26
1
transaction not working with update_attributes!
I am trying to wrap the updating of two models in a transaction and
when the transaction fails it is not rolling back.
My method is :
def update_attributes(user,params)
@user = user
@company = user.company
begin
User.transaction do
@user.update_attributes!(params[:user])
@company.update_attributes!(params[:company])
end
true
rescue
false
2006 Jul 11
3
update_attributes and save!
I notice that ActiveRecord::Base.update_attributes() calls save().
What if I want to get an exception if the save fails? Is there a way to
get the update_attributes() function plus the save! function?
Thanks,
Wes
--
Posted via http://www.ruby-forum.com/.
2006 Jan 15
0
update_attributes not working
I dont know if its me or the dodgy win-32 intall of ruby/mysql, but I
can''t seem to get update_attributes to work.
In my user controller, I have:
def update
@user = User.find(@params[''user'']["id"])
if @user.update_attributes(@params["user"])
flash["success"] = "Updated Successfully"
redirect_to :action =>
2010 Sep 01
0
Error on update_attributes with HABTM relationship
Hope someone can tell me what''s up, because this has me baffled.
I have an Image model, and a Provider model. Both are defined as
"has_and_belongs_to_many" relating to each other. In my image form
partial, I have a bit of AJAX generating the provider_ids array
dynamically from a provider AJAX search on the same page.
So for example, each time I click on a provider name that