It seems that active_record_context (by Rick O.) and optimistic
locking don’t play too well together.
When I enable active_record_context for the entire design, objects
don’t properly reload.
This is more or less what I’m doing:
while !ok {
begin
Transaction {
object1.save!
object2.save!
ok = true
}
rescue
object1.reload
object2.reload
… reapply my changes to the objects …
end
}
So, when I’m using active_record_context, which does wonders to the
database accesses, it seems that the reload doesn’t function
correctly. I don’t see any database fetches and thus, optimistic
locking keeps failing (since the other mongrel instances have changed
the data).
active_record_context overrides find to return cached values, reload
basically replaces the object’s attributes with the result of
self.class.find(self.id) so this isn’t unexpected. It would be hard for
active_record_context to also override reload so that it removes the
current object from the cache.
Is there a way for me to force reload from the database?
I just need it in a very limited number of places, so doing it
manually will not be a problem.
Is there a way for me to force reload from the database?
I just need it in a very limited number of places, so doing it
manually will not be a problem.
Not without overriding reload: reload just calls find, which ar_context
changes: you need to add code to reload that dumps the cache (and the
nice thing to do after that would be to give the changes back to rick)
nice thing to do after that would be to give the changes back to rick)
Oh, I think I may have run into this without realizing it. I just
shuffled my callbacks around a bit and it worked, but I didn’t realize
this plugin was causing the issue. Um, gmail isn’t showing the rest
of this conversation, so just send me a proper bug report at Overview - Plugins - ar-code or via
email. A patch would be lovely too of course.