Hello, how can I check if a destroy was successful? Is the object only frozen if deleted or do I have to do an additional find to see if there is a record left? What happens if an after_destroy callback returns false? Is there always a rollback? Markus
On Saturday, July 15, 2006, at 11:07 PM, Markus Kolb wrote:>Hello, > >how can I check if a destroy was successful? >Is the object only frozen if deleted or do I have to do an additional >find to see if there is a record left? > >What happens if an after_destroy callback returns false? Is there always >a rollback? > >Markus > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsYou should be able to ensure a destroy works with the proper tests, but if you really insist on wearing belts *and* suspenders you can do this. Item.destroy(params[:id]) if Item.exists?(params[:id]) # not destroyed else # destroyed end Assuming it exists in the first place. _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
Kevin Olbrich wrote on 16.07.2006 00:20:> On Saturday, July 15, 2006, at 11:07 PM, Markus Kolb wrote: >> Hello, >> >> how can I check if a destroy was successful? >> Is the object only frozen if deleted or do I have to do an additional >> find to see if there is a record left? >> >> What happens if an after_destroy callback returns false? Is there always >> a rollback?? [...]> You should be able to ensure a destroy works with the proper tests, but > if you really insist on wearing belts *and* suspenders you can do this. > Item.destroy(params[:id]) > if Item.exists?(params[:id])What happens if the DB is not available during executing the destroy and exists? ("Server shutdown in progress", "Broken pipe", "Lost connection to server during query", "server has gone away") How is this handled by AR? Markus
On Sunday, July 16, 2006, at 1:04 AM, Markus Kolb wrote:>Kevin Olbrich wrote on 16.07.2006 00:20: >> On Saturday, July 15, 2006, at 11:07 PM, Markus Kolb wrote: >>> Hello, >>> >>> how can I check if a destroy was successful? >>> Is the object only frozen if deleted or do I have to do an additional >>> find to see if there is a record left? >>> >>> What happens if an after_destroy callback returns false? Is there always >>> a rollback? >? > >[...] >> You should be able to ensure a destroy works with the proper tests, but >> if you really insist on wearing belts *and* suspenders you can do this. >> Item.destroy(params[:id]) >> if Item.exists?(params[:id]) > >What happens if the DB is not available during executing the destroy and >exists? ("Server shutdown in progress", "Broken pipe", "Lost connection >to server during query", "server has gone away") >How is this handled by AR? > >Markus > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails''exists?'' will query the database to see if that record number exists, so if the database is down it will raise an exception, I think. _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
Kevin Olbrich wrote on 16.07.2006 01:15:> On Sunday, July 16, 2006, at 1:04 AM, Markus Kolb wrote:[...]>> What happens if the DB is not available during executing the destroy and >> exists? ("Server shutdown in progress", "Broken pipe", "Lost connection >> to server during query", "server has gone away") >> How is this handled by AR?[...]> ''exists?'' will query the database to see if that record number exists, > so if the database is down it will raise an exception, I think.[...] Which exception. I can''t find any documentation to exceptions of AR. Markus
On Sunday, July 16, 2006, at 12:13 PM, Markus Kolb wrote:>Kevin Olbrich wrote on 16.07.2006 01:15: >> On Sunday, July 16, 2006, at 1:04 AM, Markus Kolb wrote: >[...] >>> What happens if the DB is not available during executing the destroy and >>> exists? ("Server shutdown in progress", "Broken pipe", "Lost connection >>> to server during query", "server has gone away") >>> How is this handled by AR? >[...] > >> ''exists?'' will query the database to see if that record number exists, >> so if the database is down it will raise an exception, I think. >[...] > >Which exception. I can''t find any documentation to exceptions of AR. > >Markus > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsTry running your application with your database turned off and see what happens. _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
On Sunday, July 16, 2006, at 12:28 PM, Kevin Olbrich wrote:> >On Sunday, July 16, 2006, at 12:13 PM, Markus Kolb wrote: >>Kevin Olbrich wrote on 16.07.2006 01:15: >>> On Sunday, July 16, 2006, at 1:04 AM, Markus Kolb wrote: >>[...] >>>> What happens if the DB is not available during executing the >>>>destroy and >>>> exists? ("Server shutdown in progress", "Broken pipe", "Lost connection >>>> to server during query", "server has gone away") >>>> How is this handled by AR? >>[...] >> >>> ''exists?'' will query the database to see if that record number exists, >>> so if the database is down it will raise an exception, I think. >>[...] >> >>Which exception. I can''t find any documentation to exceptions of AR. >> >>Markus >> >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails > >Try running your application with your database turned off and see what >happens. > >_Kevin >www.sciwerks.com > >-- >Posted with http://DevLists.com. Sign up and save your mailbox. >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsI get this exception when I do it. ''Can''t connect to local MySQL server through socket ''/tmp/mysql.sock'' (2)'' _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
Kevin Olbrich wrote on 16.07.2006 14:36:> On Sunday, July 16, 2006, at 12:28 PM, Kevin Olbrich wrote: >> On Sunday, July 16, 2006, at 12:13 PM, Markus Kolb wrote: >>> Kevin Olbrich wrote on 16.07.2006 01:15: >>>> On Sunday, July 16, 2006, at 1:04 AM, Markus Kolb wrote: >>> [...] >>>>> What happens if the DB is not available during executing the >>>>> destroy and >>>>> exists? ("Server shutdown in progress", "Broken pipe", "Lost connection >>>>> to server during query", "server has gone away") >>>>> How is this handled by AR? >>> [...] >>> >>>> ''exists?'' will query the database to see if that record number exists, >>>> so if the database is down it will raise an exception, I think. >>> [...] >>> >>> Which exception. I can''t find any documentation to exceptions of AR.[...]> I get this exception when I do it. > > ''Can''t connect to local MySQL server through socket ''/tmp/mysql.sock'' (2)''Is the exception from destroy or exists?() I think it''s not coming from exists?() because it rescues from exceptions and returns false. Is there really no documentation of the exception classes and how they are used in AR? It is horror to go through the source to find possibilities of exceptions. Kevin, thanks for your help.
> Is there really no documentation of the exception classes and how they > are used in AR? It is horror to go through the source to find > possibilities of exceptions.http://dev.rubyonrails.org/svn/rails/trunk/activerecord/lib/active_record/base.rb All the ActiveRecord exceptions are defined at the top. -- Rick Olson http://techno-weenie.net
On Sunday, July 16, 2006, at 4:46 PM, Markus Kolb wrote:>Kevin Olbrich wrote on 16.07.2006 14:36: >> On Sunday, July 16, 2006, at 12:28 PM, Kevin Olbrich wrote: >>> On Sunday, July 16, 2006, at 12:13 PM, Markus Kolb wrote: >>>> Kevin Olbrich wrote on 16.07.2006 01:15: >>>>> On Sunday, July 16, 2006, at 1:04 AM, Markus Kolb wrote: >>>> [...] >>>>>> What happens if the DB is not available during executing the >>>>>> destroy and >>>>>> exists? ("Server shutdown in progress", "Broken pipe", "Lost >>>>>>connection >>>>>> to server during query", "server has gone away") >>>>>> How is this handled by AR? >>>> [...] >>>> >>>>> ''exists?'' will query the database to see if that record number exists, >>>>> so if the database is down it will raise an exception, I think. >>>> [...] >>>> >>>> Which exception. I can''t find any documentation to exceptions of AR. > >[...] >> I get this exception when I do it. >> >> ''Can''t connect to local MySQL server through socket ''/tmp/ >>mysql.sock'' (2)'' > >Is the exception from destroy or exists?() >I think it''s not coming from exists?() because it rescues from >exceptions and returns false. > >Is there really no documentation of the exception classes and how they >are used in AR? It is horror to go through the source to find >possibilities of exceptions. > >Kevin, thanks for your help. > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/railsI generated this exception by turning off mysql and trying to do anything with my rails app. The problem you are much more likely to encounter is if a record is destoyed by another user before your request is processed. You could check your params[:id] for a valid record number before proceeding with the destroy. In fact, I use a before filter for this very thing. At least you can do something like this... def destroy begin Item.find(params[:id]).destroy rescue # an exception was raised... db down, record not found, etc... end end _Kevin www.sciwerks.com -- Posted with http://DevLists.com. Sign up and save your mailbox.
Rick Olson wrote on 16.07.2006 19:00:>> Is there really no documentation of the exception classes and how they >> are used in AR? It is horror to go through the source to find >> possibilities of exceptions. > > http://dev.rubyonrails.org/svn/rails/trunk/activerecord/lib/active_record/base.rb > > > All the ActiveRecord exceptions are defined at the top.I know but there is no doc and I think 99% of methods have no information which exceptions they could raise and because of which situation. Without such information it''s nearly impossible to use exceptions for error detection and rescue handling. It shouldn''t be an exception to describe exceptions ;(
> I know but there is no doc and I think 99% of methods have no > information which exceptions they could raise and because of which > situation. Without such information it''s nearly impossible to use > exceptions for error detection and rescue handling. > It shouldn''t be an exception to describe exceptions ;(Doc patches are excepted. har :) -- Rick Olson http://techno-weenie.net
This might be fruitful (I''m sure there''s a better regex for this): find vendor/rails/activerecord -name *.rb -exec grep -n "[^_]raise[ \t]" ''{}'' \; -print Partial results: activerecord/lib/active_record/associations/association_proxy.rb 983: raise ArgumentError, '':dependent and :exclusively_dependent are mutually exclusive options. You may specify one or the other.'' 1010: raise ArgumentError, ''The :dependent option expects either :destroy, :delete_all, or :nullify'' 1023: raise ArgumentError, "The :dependent option expects either :destroy or :nullify." 1285: raise ConfigurationError, "Association named ''#{ associations }'' was not found; perhaps you misspelled it?" On Sunday, July 16, 2006, at 10:33 PM, Rick Olson wrote:>> I know but there is no doc and I think 99% of methods have no >> information which exceptions they could raise and because of which >> situation. Without such information it''s nearly impossible to use >> exceptions for error detection and rescue handling. >> It shouldn''t be an exception to describe exceptions ;( > >Doc patches are excepted. har :) > > >-- >Rick Olson >http://techno-weenie.net >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails-- Posted with http://DevLists.com. Sign up and save your mailbox.