Skip to content

Commit

Permalink
Closes #4941: commit argument is now required argument in a custom sc…
Browse files Browse the repository at this point in the history
…ript's run() method
  • Loading branch information
jeremystretch committed Aug 21, 2020
1 parent e02590a commit 2339fe2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/release-notes/index.md
7 changes: 7 additions & 0 deletions docs/release-notes/version-2.10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# NetBox v2.10

## v2.10-beta1 (FUTURE)

### Other Changes

* [#4941](https://github.com/netbox-community/netbox/issues/4941) - `commit` argument is now required argument in a custom script's `run()` method
15 changes: 1 addition & 14 deletions netbox/extras/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,24 +428,11 @@ 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 beginning "
f"with NetBox v2.10."
)

with change_logging(request):

try:
with transaction.atomic():
script.output = script.run(**kwargs)
script.output = script.run(data=data, commit=commit)
job_result.set_status(JobResultStatusChoices.STATUS_COMPLETED)

if not commit:
Expand Down

0 comments on commit 2339fe2

Please sign in to comment.