Forum: Ruby on Rails db connection returns stale values

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fcfb86addd7d70c57f113fedfcb9fb6a?d=identicon&s=25 Tom Shealy (tom_302)
on 2013-05-20 15:50
(Received via mailing list)
Hello,

I'm working on a rails 3 app for a legacy oracle db.

I have a controller that saves object graphs
(accepts_nested_attributes_for) but I noticed the post-update JSON
response
still contains the pre-update values.

After some debugging, it appears the database connection is returning
stale
values (find(), reload(), etc., all return pre-update values; but SQL
clients and other ActiveRecord connections find post-update values,
confirming the update was written successfully to the database).

A call to ActiveRecord::Base.establish_connection fixes the problem for
the
'stale' connection.

controller:

def update
  #@default_model.update_attributes(params[@model_name])
  @default_model.assign_attributes(params[@model_name])
  Graph::Helper.save(@default_model)  #custom save() for legacy version
control

  debugger
  @default_model.some_association.updated_field   #still shows
pre-update
value
  @default_model.reload
  @default_model.some_association.updated_field   #still shows
pre-update
value
  @default_model.find(id).some_association.updated_field  #still shows
pre-update value

  ActiveRecord::Base.establish_connection(:oracledb);  #THIS LINE SEEMS
TO
FIX THE PROBLEM.

  @default_model.reload
  @default_model.some_association.updated_field  #shows the correct,
updated value.

...
end

For what it's worth, I'm using jruby in threadsafe mode with the oracle
jdbc activerecord adapter.  Any suggestions on where to look to get to
the
bottom of the stale values?

Thanks,
Tom
This topic is locked and can not be replied to.