It seems that active_record_context (by Rick Olson) 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: http://www.activereload.net/2007/5/23/spend-less-time-in-the-database-and-more-time-outdoors Any ideas? Thanks, Helzer --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Sep-26 16:07 UTC
Re: active_record_context, optimistic locking and object rel
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. Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Fred, 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. Helzer --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2007-Sep-26 16:23 UTC
Re: active_record_context, optimistic locking and object rel
helzer wrote:> Thanks Fred, > > 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) Fred -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick Olson
2007-Sep-26 17:51 UTC
Re: active_record_context, optimistic locking and object rel
On 9/26/07, Frederick Cheung <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > helzer wrote: > > Thanks Fred, > > > > 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)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 http://ar-code.lighthouseapp.com/projects/3108-plugins/overview or via email. A patch would be lovely too of course. -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Rick, Funny thing, gmail stopped notifying me about thread additions too... I just created the ticket in lighthouse about this. http://ar-code.lighthouseapp.com/projects/3108-plugins/tickets/5-active_record_context-prevents-object-reload-from-database Thanks, Amir --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---