1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Log a warning for scripts whose run() method does not accept a commit argument

This commit is contained in:
Jeremy Stretch
2020-08-03 13:56:10 -04:00
parent 31e65a09e8
commit b410674f9e
2 changed files with 6 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import logging
import os
import pkgutil
import traceback
import warnings
from collections import OrderedDict
import yaml
@ -405,12 +406,16 @@ def run_script(data, request, commit=True, *args, **kwargs):
# Add the current request as a property of the script
script.request = request
# TODO: Drop backward-compatibility for absent 'commit' argument in v2.10
# Determine whether the script accepts a 'commit' argument (this was introduced in v2.7.8)
kwargs = {
'data': data
}
if 'commit' in inspect.signature(script.run).parameters:
kwargs['commit'] = commit
else:
warnings.warn(f"The run() method of script {script} should support a 'commit' argument. This will be required "
f"beginning with NetBox v2.10.")
try:
with transaction.atomic():