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

Abierto
#121 0 comentarios 0 reacciones 1 asignado Ver en GitHub

Los mantenedores suelen responder en 1 día

@pheus ya está trabajando en esto.

Desde el 6/11/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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.

Lenguaje dominante
Python
Estrellas
8
Forks
0
Merge medio
11 h 22 min
PR fusionados (30 d)
40

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de netbox-community/netbox-scripts

Todos los issues de netbox-community/netbox-scripts

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.