On Wed, March 6, 2013 04:54, Frederick Cheung wrote:
> On Tue, Mar 5, 2013 at 7:32 PM, byrnejb <[email protected]> wrote:
>
>> I have this code in a working RoR-3.1 app:
>>
>>   # save
>>   #
>>   # Override AR save method to catch DBMS specific errors
>>   # such as uniqueness constraint violations
>>
>
> Where is this code? in a model, in module that is included into
> various models, somewhere else?

It is contained in a model:

class Currency < ActiveRecord::Base
  include HLLActiveRow

  after_save( :save_errors )
.  .  .
  # save
  #
  # Override AR save method to catch DBMS specific errors
  # such as uniqueness constraint violations
  def save( * )
    begin
      puts( "I go" )
      super
      puts( "I return" )
      rescue ActiveRecord::StatementInvalid => this_exception
        errors.add( currency_code, hll_ar_exception( this_exception ) )
        # errors.add_to_base(hll_ar_exception(this_exception))
        false
    end
  end
.  .  .

I see that in the new persistence layer save is now deifined thus:



# File activerecord/lib/active_record/persistence.rb, line 82
def save(*)
  begin
    create_or_update
  rescue ActiveRecord::RecordInvalid
    false
  end
end

Which bears some similarity to what I was doing for previous versions.
 The rescue was added to persistence.rb in this commit two years ago:

https://github.com/rails/rails/commit/656e7b08073fa4e620a6d9ce0de554f8f5be96bb


But my code has been working subsequent to this up to v3.2. Something
else has changed to cause the effect I am now experiencing.  The main
problem from my point of view is that I expect the save call to return
to the invoking method immediately after the point super is invoked
and that is not happening.  That is what I find astonishing.

>
> As an aside recent versions of rails raise
> ActiveRecord::RecordNotUnique in
> such cases, although this is a subclass of
> ActiveRecord::StatementInvalid
> so shouldn't change behaviour as far as you're concern. You're also
> changing the signature of save although I don't think that is related
> to the problem at hand.

As far as I can see, save rescues but does not re-raise such
exceptions so I do not know where it is being returned from.


-- 
***          E-Mail is NOT a SECURE channel          ***
James B. Byrne                mailto:[email protected]
Harte & Lyne Limited          http://www.harte-lyne.ca
9 Brockley Drive              vox: +1 905 561 1241
Hamilton, Ontario             fax: +1 905 561 0757
Canada  L8E 3C3

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to