Failed post-commit callback reports committed changes as reverted and drops events

オープン
#121 コメント 0 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@pheus がすでに取り組んでいます。

2026年11月6日 から。

評価

この issue はまだ評価されていません。

説明

app: scripts Bucket: KTLO severity: low status: accepted type: bug
Plugin Version

v0.0.1

NetBox Version

v4.7.1

Python Version

3.12

Steps to Reproduce
  1. Create a Script Project, then upload and activate a Script File containing:
    from django.db import transaction
    from extras.models import Tag
    
    from netbox_scripts import Script
    
    
    def fail():
        raise RuntimeError('the cache write failed after the commit')
    
    
    class CommitThenFail(Script):
        def run(self, data, commit):
            Tag.objects.create(
                name='kept-by-commit',
                slug='kept-by-commit',
            )
            transaction.on_commit(fail)
            return 'done'
    
  2. Optionally, configure an Event Rule for newly created Tags to observe event delivery.
  3. Run the Script with Commit changes enabled.
  4. Open the Job result and check the Tags list.
Expected Behavior

The Job reports the commit callback's exception but does not claim that the database changes were reverted, since they were already committed.

The created Tag remains, and its object-change event is processed normally so that matching Event Rules can run.

Observed Behavior

The Tag kept-by-commit exists, but the Job is marked as Failed and its log incorrectly reports:

Database changes have been reverted because the run did not finish.

The exception handler also clears the pending object-change events. As a result, matching Event Rules and webhooks are not triggered.

This happens because Django runs transaction.on_commit() callbacks after committing the transaction. An exception raised by a callback registered with the default robust=False propagates into the Script runner, which handles it as though the transaction had been rolled back.

主要言語
Python
スター
8
フォーク
0
平均マージ
11時間 22分
マージ済み PR(30日)
40

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

netbox-community/netbox-scripts のほかの issue

netbox-community/netbox-scripts の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。