mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 09:51:22 -06:00
Closes #18224: Apply all registered request processors when running custom scripts
This commit is contained in:
parent
c0fec28b2a
commit
0b9ead3e8b
@ -1,14 +1,14 @@
|
|||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
from contextlib import nullcontext
|
from contextlib import ExitStack
|
||||||
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from core.signals import clear_events
|
from core.signals import clear_events
|
||||||
from extras.models import Script as ScriptModel
|
from extras.models import Script as ScriptModel
|
||||||
from netbox.context_managers import event_tracking
|
|
||||||
from netbox.jobs import JobRunner
|
from netbox.jobs import JobRunner
|
||||||
|
from netbox.registry import registry
|
||||||
from utilities.exceptions import AbortScript, AbortTransaction
|
from utilities.exceptions import AbortScript, AbortTransaction
|
||||||
from .utils import is_report
|
from .utils import is_report
|
||||||
|
|
||||||
@ -100,5 +100,7 @@ class ScriptJob(JobRunner):
|
|||||||
|
|
||||||
# Execute the script. If commit is True, wrap it with the event_tracking context manager to ensure we process
|
# Execute the script. If commit is True, wrap it with the event_tracking context manager to ensure we process
|
||||||
# change logging, event rules, etc.
|
# change logging, event rules, etc.
|
||||||
with event_tracking(request) if commit else nullcontext():
|
with ExitStack() as stack:
|
||||||
|
for request_processor in registry['request_processors']:
|
||||||
|
stack.enter_context(request_processor(request))
|
||||||
self.run_script(script, request, data, commit)
|
self.run_script(script, request, data, commit)
|
||||||
|
Loading…
Reference in New Issue
Block a user