I'm a bit puzzled with an ActiveRecord::StatementInvalid exception
that's apparently being thrown twice.
I'm using Rails 2.3.3 and Postgres, and inside the Feed Model I have
has_many :entries, :dependent => :delete_all
# log saving feed
save! # will fail if an exception is thrown below
# log saving entry
entry.save! # can fail because of duplicate key values
rescue ActiveRecord::StatementInvalid => e
# log exception caught
# log the error in the db (Log Model)
* Saving entry
PGError: ERROR: duplicate key value ... : INSERT INTO "entries" ...
* Exception caught
INSERT INTO "logs" ...
* Saving feed
UPDATE "feeds" ...
PGError: ERROR: duplicate key value ... : INSERT INTO "entries"
ActiveRecord::StatementInvalid: PGError: ERROR: duplicate key ...
The last exception that terminates execution was (or should have been)
caught inside the begin/rescue block. Why is it thrown again when the
feed is saved, if the transaction was rolled back?
Any hints much appreciated!