Breaking change in custom scripts called with api on v4.x #9672

Closed
opened 2025-12-29 21:20:41 +01:00 by adam · 3 comments
Owner

Originally created by @Leon-Pay on GitHub (May 14, 2024).

Deployment Type

Self-hosted

NetBox Version

v4.0.1

Python Version

3.11

Steps to Reproduce

Create a custom script and try to call it from the API. The old url has changed to an id and when calling the script from the API it will throw an error.

Expected Behavior

The script runs when called with the API.
The api url used to be /api/extras/scripts/ssl_checker_custom_script.SSLChecker/
Like: https://github.com/netbox-community/netbox/blob/develop/docs/customization/custom-scripts.md#via-the-api

Observed Behavior

Url has changed to /api/extras/scripts/1

Trying to run the custom script, with the new url will throw an error:

const url = '/api/extras/scripts/1/';
const sendData = { data: { certificate: id }, commit: true };

fetch(url, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-CSRFToken': csrf_token
  },
  body: JSON.stringify(sendData)
})
netbox-worker-1        | 14:42:31 default: extras.scripts.run_script(commit=True, data={'certificate': '2'}, job=<Job: a00b207c-ce2c-422e-b0f7-8acbac05b42d>, request=<utilities.request.NetBoxFakeRequest object at 0xffff77998d50>) (a00b207c-ce2c-422e-b0f7-8acbac05b42d)
netbox-1               | Internal Server Error: /api/extras/scripts/1/
netbox-1               | Traceback (most recent call last):
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
netbox-1               |     response = get_response(request)
netbox-1               |                ^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
netbox-1               |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
netbox-1               |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper
netbox-1               |     return view_func(request, *args, **kwargs)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/viewsets.py", line 124, in view
netbox-1               |     return self.dispatch(request, *args, **kwargs)
netbox-1               |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 509, in dispatch
netbox-1               |     response = self.handle_exception(exc)
netbox-1               |                ^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 469, in handle_exception
netbox-1               |     self.raise_uncaught_exception(exc)
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
netbox-1               |     raise exc
netbox-1               |   File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch
netbox-1               |     response = handler(request, *args, **kwargs)
netbox-1               |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
netbox-1               |   File "/opt/netbox/netbox/extras/api/views.py", line 243, in post
netbox-1               |     script.result = Job.enqueue(
netbox-1               |     ^^^^^^^^^^^^^
netbox-1               | AttributeError: property 'result' of 'Script' object has no setter

Running in the GUI (and getting the correct results):

netbox-worker-1        | 14:41:50 default: extras.scripts.run_script(commit=True, data={'certificate': <SSLCertificate: https://xxxx.xxxx.xxx>}, job=<Job: 14ffa8e8-c81d-4084-bc59-e1ffa36ff47b>, request=<utilities.request.NetBoxFakeRequest object at 0xffff77acbd10>) (14ffa8e8-c81d-4084-bc59-e1ffa36ff47b)
Originally created by @Leon-Pay on GitHub (May 14, 2024). ### Deployment Type Self-hosted ### NetBox Version v4.0.1 ### Python Version 3.11 ### Steps to Reproduce Create a custom script and try to call it from the API. The old url has changed to an id and when calling the script from the API it will throw an error. ### Expected Behavior The script runs when called with the API. The api url used to be /api/extras/scripts/ssl_checker_custom_script.SSLChecker/ Like: https://github.com/netbox-community/netbox/blob/develop/docs/customization/custom-scripts.md#via-the-api ### Observed Behavior Url has changed to /api/extras/scripts/1 Trying to run the custom script, with the new url will throw an error: ``` const url = '/api/extras/scripts/1/'; const sendData = { data: { certificate: id }, commit: true }; fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrf_token }, body: JSON.stringify(sendData) }) ``` ``` netbox-worker-1 | 14:42:31 default: extras.scripts.run_script(commit=True, data={'certificate': '2'}, job=<Job: a00b207c-ce2c-422e-b0f7-8acbac05b42d>, request=<utilities.request.NetBoxFakeRequest object at 0xffff77998d50>) (a00b207c-ce2c-422e-b0f7-8acbac05b42d) netbox-1 | Internal Server Error: /api/extras/scripts/1/ netbox-1 | Traceback (most recent call last): netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner netbox-1 | response = get_response(request) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response netbox-1 | response = wrapped_callback(request, *callback_args, **callback_kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/django/views/decorators/csrf.py", line 65, in _view_wrapper netbox-1 | return view_func(request, *args, **kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/viewsets.py", line 124, in view netbox-1 | return self.dispatch(request, *args, **kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 509, in dispatch netbox-1 | response = self.handle_exception(exc) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 469, in handle_exception netbox-1 | self.raise_uncaught_exception(exc) netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception netbox-1 | raise exc netbox-1 | File "/opt/netbox/venv/lib/python3.11/site-packages/rest_framework/views.py", line 506, in dispatch netbox-1 | response = handler(request, *args, **kwargs) netbox-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ netbox-1 | File "/opt/netbox/netbox/extras/api/views.py", line 243, in post netbox-1 | script.result = Job.enqueue( netbox-1 | ^^^^^^^^^^^^^ netbox-1 | AttributeError: property 'result' of 'Script' object has no setter ``` Running in the GUI (and getting the correct results): ``` netbox-worker-1 | 14:41:50 default: extras.scripts.run_script(commit=True, data={'certificate': <SSLCertificate: https://xxxx.xxxx.xxx>}, job=<Job: 14ffa8e8-c81d-4084-bc59-e1ffa36ff47b>, request=<utilities.request.NetBoxFakeRequest object at 0xffff77acbd10>) (14ffa8e8-c81d-4084-bc59-e1ffa36ff47b) ```
adam added the type: bugstatus: duplicate labels 2025-12-29 21:20:41 +01:00
adam closed this issue 2025-12-29 21:20:41 +01:00
Author
Owner

@MalfuncEddie commented on GitHub (May 14, 2024):

can confirm (related/dup) #16123

@MalfuncEddie commented on GitHub (May 14, 2024): can confirm (related/dup) #16123
Author
Owner

@jeremystretch commented on GitHub (May 14, 2024):

Thank you for submitting this issue, however it appears that this topic has already been raised. Please see issue #16123 for further discussion.

@jeremystretch commented on GitHub (May 14, 2024): Thank you for submitting this issue, however it appears that this topic has already been raised. Please see issue #16123 for further discussion.
Author
Owner

@bitcollector1 commented on GitHub (May 14, 2024):

works great now! thanks

@bitcollector1 commented on GitHub (May 14, 2024): works great now! thanks
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9672