Forum: Ruby on Rails db connection returns stale values

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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.