db connection returns stale values

16 views
Skip to first unread message

tom_302

unread,
May 20, 2013, 9:48:43 AM5/20/13
to rubyonra...@googlegroups.com
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

Reply all
Reply to author
Forward
0 new messages