Project

General

Profile

Actions

Bug #19698

closed

save_with_unique_name hides other transaction errors

Added by Peter Amstutz over 1 year ago. Updated over 1 year ago.

Status:
Resolved
Priority:
Normal
Assigned To:
Category:
API
Target version:
Story points:
-
Release relationship:
Auto

Description

save_with_unique_name works like this:

      conn.exec_query 'SAVEPOINT save_with_unique_name'
      begin
        save!
      rescue ActiveRecord::RecordNotUnique => rn
        # tries different names, uses 
        # "ROLLBACK TO SAVEPOINT" 
        # to recover from transaction errors
      ensure
        conn.exec_query 'RELEASE SAVEPOINT save_with_unique_name'
      end

It seems that if some other transaction error happens, then

  1. transaction is aborted
  2. the "ensure" block runs "RELEASE SAVEPOINT"
  3. because the transaction is aborted, it rejects "RELEASE SAVEPOINT"
  4. it raises a new error about not being able to accept "RELEASE SAVEPOINT" instead of propagating the original error

The result is a cryptic error about ignoring commands in a failed transaction and not the original error that gives some indication of what was wrong.

I need to read up on savepoints, but it may be that there's no real benefit to releasing the savepoint here, presumably it will be released when the transaction is closed either way.


Subtasks 1 (0 open1 closed)

Task #19723: Review 19698-masked-errorResolvedTom Clegg11/15/2022Actions
Actions

Also available in: Atom PDF