Repository: netbox-community/netbox
Pull request: 17635 fix script AbortTransaction
### Fixes: #17635 



Problem statement:
Report raises AbortTransaction() when commit=False and log_failure() has been used
### Deployment Type

Self-hosted

### NetBox Version

v4.1.2

### Python Version

3.11

### Steps to Reproduce

Create a script that logs a failure. Run the script with commit=False
```
from extras.scripts import Script

class LogFailure(Script):
  description = "Log one failure"

  def test_error_behavior(self):
    self.log_failure("This is a test failure, not a script failure")
```

### Expected Behavior

The script will log one 'Failure' line, rollback database changes, and complete

### Observed Behavior

The script logs appropriate, but adds an additional failure, as show below, before rolling back DB changes
```
An exception occurred: AbortTransaction:

Traceback (most recent call last):
  File "/opt/netbox/netbox/extras/jobs.py", line 47, in run_script
    raise AbortTransaction()
utilities.exceptions.AbortTransaction
```

Hints from issue discussion:

Commit message: 17635 fix script AbortTransaction

Patch to review:
diff --git a/netbox/extras/jobs.py b/netbox/extras/jobs.py
index 64a7d6a69b4..9b620045020 100644
--- a/netbox/extras/jobs.py
+++ b/netbox/extras/jobs.py
@@ -51,6 +51,9 @@ def run_script(self, script, request, data, commit):
                     logger.warning("Script failed")
                     raise
 
+        except AbortTransaction:
+            # this is already handled above.
+            pass
         except Exception as e:
             if type(e) is AbortScript:
                 msg = _("Script aborted with error: ") + str(e)


Code review comments:
diff_hunk: @@ -51,6 +51,9 @@ def run_script(self, script, request, data, commit):
                     logger.warning("Script failed")
                     raise
 
+        except AbortTransaction:
+            # this is already handled above.
+            pass
path: netbox/extras/jobs.py
text: @user1:
This doesn't need to be caught again; we can just avoid re-raising it on line 52.